// Worker using REQ socket to do load-balancing // static void * worker_task(void *args) { zctx_t *ctx = zctx_new(); void *worker = zsocket_new(ctx, ZMQ_REQ); #if (defined (WIN32)) zsocket_connect(worker, "tcp://localhost:5673"); // backend #else zsocket_connect(worker, "ipc://backend.ipc"); #endif // Tell broker we're ready for work zframe_t *frame = zframe_new(WORKER_READY, strlen(WORKER_READY)); zframe_send(&frame, worker, 0); // Process messages as they arrive while (1) { zmsg_t *msg = zmsg_recv(worker); if (!msg) break; // Interrupted zframe_print(zmsg_last(msg), "Worker: "); zframe_reset(zmsg_last(msg), "OK", 2); zmsg_send(&msg, worker); } zctx_destroy(&ctx); return NULL; }
static void* worker_routine(void* arg) { zmsg_t* msg; zframe_t* frame; zctx_t* ctx = zctx_new(); void* worker = zsocket_new(ctx, ZMQ_REQ); zsocket_connect(worker, "ipc://%s-localbe.ipc", self); frame = zframe_new(WORKER_READY, 1); zframe_send(&frame, worker, 0); while (1) { msg = zmsg_recv(worker); if (!msg) break; zframe_print(zmsg_last(msg), "Worker: "); zframe_reset(zmsg_last(msg), "OK", 2); zmsg_send(&msg, worker); } zctx_destroy(&ctx); return NULL; }
static void * client_task (void *args) { zctx_t *ctx = zctx_new (); void *client = zsocket_new (ctx, ZMQ_DEALER); // Set random identity to make tracing easier char identity [10]; sprintf (identity, "%04X-%04X", randof (0x10000), randof (0x10000)); zsocket_set_identity (client, identity); zsocket_connect (client, "tcp://localhost:5570"); zmq_pollitem_t items [] = { { client, 0, ZMQ_POLLIN, 0 } }; int request_nbr = 0; while (true) { // Tick once per second, pulling in arriving messages int centitick; for (centitick = 0; centitick < 100; centitick++) { zmq_poll (items, 1, 10 * ZMQ_POLL_MSEC); if (items [0].revents & ZMQ_POLLIN) { zmsg_t *msg = zmsg_recv (client); zframe_print (zmsg_last (msg), identity); zmsg_destroy (&msg); } } zstr_send (client, "request #%d"); } zctx_destroy (&ctx); return NULL; }
int handle_event(zloop_t *loop, zsock_t *reader, void *args) { // initialization ubx_block_t *b = (ubx_block_t *) args; struct zmq_receiver_info *inf = (struct zmq_receiver_info*) b->private_data; printf("zmq_receiver: data available.\n"); zframe_t *frame = zframe_recv (reader); // print out frame data zframe_print (frame, NULL); // move to step function? ubx_type_t* type = ubx_type_get(b->ni, "unsigned char"); ubx_data_t msg; msg.data = (void *)zframe_data(frame); msg.len = zframe_size(frame); msg.type = type; //hexdump((unsigned char *)msg.data, msg.len, 16); __port_write(inf->ports.zmq_in, &msg); /* Inform potential observers ? */ // clean up temporary frame object zframe_destroy (&frame); return 1; }
JNIEXPORT void JNICALL Java_org_zeromq_czmq_Zframe__1_1print (JNIEnv *env, jclass c, jlong self, jstring prefix) { char *prefix_ = (char *) (*env)->GetStringUTFChars (env, prefix, NULL); zframe_print ((zframe_t *) (intptr_t) self, prefix_); (*env)->ReleaseStringUTFChars (env, prefix, prefix_); }
static void listener_thread (void *args, zctx_t *ctx, void *pipe) { // Print everything that arrives on pipe while (true) { zframe_t *frame = zframe_recv (pipe); if (!frame) break; // Interrupted zframe_print (frame, NULL); zframe_destroy (&frame); } }
static VALUE rb_czmq_frame_print(int argc, VALUE *argv, VALUE obj) { VALUE prefix; const char *print_prefix = NULL; ZmqGetFrame(obj); rb_scan_args(argc, argv, "01", &prefix); if (NIL_P(prefix)) { print_prefix = ""; } else { Check_Type(prefix, T_STRING); print_prefix = RSTRING_PTR(prefix); } zframe_print(frame, (char *)print_prefix); return Qnil; }
int main (int argc, char *argv []) { int verbose = (argc > 1 && streq (argv [1], "-v")); mdcli_t *session = mdcli_new ("tcp://localhost:5555", verbose); // 1. Send 'echo' request to Titanic zmsg_t *request = zmsg_new (); zmsg_addstr (request, "echo"); zmsg_addstr (request, "Hello world"); zmsg_t *reply = s_service_call ( session, "titanic.request", &request); zframe_t *uuid = NULL; if (reply) { uuid = zmsg_pop (reply); zmsg_destroy (&reply); zframe_print (uuid, "I: request UUID "); } // 2. Wait until we get a reply while (!zctx_interrupted) { zclock_sleep (100); request = zmsg_new (); zmsg_add (request, zframe_dup (uuid)); zmsg_t *reply = s_service_call ( session, "titanic.reply", &request); if (reply) { char *reply_string = zframe_strdup (zmsg_last (reply)); printf ("Reply: %s\n", reply_string); free (reply_string); zmsg_destroy (&reply); // 3. Close request request = zmsg_new (); zmsg_add (request, zframe_dup (uuid)); reply = s_service_call (session, "titanic.close", &request); zmsg_destroy (&reply); break; } else { printf ("I: no reply yet, trying again...\n"); zclock_sleep (5000); // Try again in 5 seconds } } zframe_destroy (&uuid); mdcli_destroy (&session); return 0; }
void zmsg_print (zmsg_t *self) { assert (self); assert (zmsg_is (self)); if (!self) { zsys_debug ("(NULL)"); return; } zframe_t *frame = zmsg_first (self); while (frame) { zframe_print (frame, NULL); frame = zmsg_next (self); } }
static void * worker_task (void *args) { zctx_t *ctx = zctx_new (); void *worker = zsocket_new (ctx, ZMQ_REQ); zsocket_connect (worker, "ipc://%s-localbe.ipc", self); // Tell broker we're ready for work zframe_t *frame = zframe_new (WORKER_READY, 1); zframe_send (&frame, worker, 0); // Process messages as they arrive while (true) { zmsg_t *msg = zmsg_recv (worker); if (!msg) break; // Interrupted zframe_print (zmsg_last (msg), "Worker: "); zframe_reset (zmsg_last (msg), "OK", 2); zmsg_send (&msg, worker); } zctx_destroy (&ctx); return NULL; }
/// // Send message to zsys log sink (may be stdout, or system facility as // configured by zsys_set_logstream). Prefix shows before frame, if not null. void QmlZframe::print (const QString &prefix) { zframe_print (self, prefix.toUtf8().data()); };
Z K2(zframeprint){PC(x); zframe_print(VSK(x), ys); RZ;}
void zproto_example_print (zproto_example_t *self) { assert (self); switch (self->id) { case ZPROTO_EXAMPLE_LOG: zsys_debug ("ZPROTO_EXAMPLE_LOG:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" version=3"); zsys_debug (" level=%ld", (long) self->level); zsys_debug (" event=%ld", (long) self->event); zsys_debug (" node=%ld", (long) self->node); zsys_debug (" peer=%ld", (long) self->peer); zsys_debug (" time=%ld", (long) self->time); zsys_debug (" host='%s'", self->host); if (self->data) zsys_debug (" data='%s'", self->data); else zsys_debug (" data="); break; case ZPROTO_EXAMPLE_STRUCTURES: zsys_debug ("ZPROTO_EXAMPLE_STRUCTURES:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" aliases="); if (self->aliases) { char *aliases = (char *) zlist_first (self->aliases); while (aliases) { zsys_debug (" '%s'", aliases); aliases = (char *) zlist_next (self->aliases); } } zsys_debug (" headers="); if (self->headers) { char *item = (char *) zhash_first (self->headers); while (item) { zsys_debug (" %s=%s", zhash_cursor (self->headers), item); item = (char *) zhash_next (self->headers); } } else zsys_debug ("(NULL)"); break; case ZPROTO_EXAMPLE_BINARY: zsys_debug ("ZPROTO_EXAMPLE_BINARY:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" flags=[ ... ]"); zsys_debug (" public_key=[ ... ]"); zsys_debug (" identifier="); if (self->identifier) zsys_debug (" %s", zuuid_str_canonical (self->identifier)); else zsys_debug (" (NULL)"); zsys_debug (" address="); if (self->address) zframe_print (self->address, NULL); else zsys_debug ("(NULL)"); zsys_debug (" content="); if (self->content) zmsg_print (self->content); else zsys_debug ("(NULL)"); break; case ZPROTO_EXAMPLE_TYPES: zsys_debug ("ZPROTO_EXAMPLE_TYPES:"); zsys_debug (" sequence=%ld", (long) self->sequence); zsys_debug (" client_forename='%s'", self->client_forename); zsys_debug (" client_surname='%s'", self->client_surname); zsys_debug (" client_mobile='%s'", self->client_mobile); zsys_debug (" client_email='%s'", self->client_email); zsys_debug (" supplier_forename='%s'", self->supplier_forename); zsys_debug (" supplier_surname='%s'", self->supplier_surname); zsys_debug (" supplier_mobile='%s'", self->supplier_mobile); zsys_debug (" supplier_email='%s'", self->supplier_email); break; } }