Listing 4 in C

// NOTE: do NOT reuse this example code!
static char *topic_str = "msg.x|";

void* pub_worker(void* arg){
void *ctx = arg;
assert(ctx);

void *qskt = zmq_socket(ctx, ZMQ_REP);
assert(qskt);

int rc = zmq_connect(qskt, "inproc://querys");
assert(rc == 0);

void *pubskt = zmq_socket(ctx, ZMQ_PUB);
assert(pubskt);

rc = zmq_bind(pubskt, "inproc://publish");
assert(rc == 0);

uint8_t cmd;
uint32_t nb;
zmq_msg_t topic_msg, cmd_msg, nb_msg, resp_msg;

zmq_msg_init_data(&topic_msg, topic_str, strlen(topic_str) , NULL, NULL);

fprintf(stdout,"WORKER: ready to receive messages\n");
// NOTE: do NOT reuse this example code, It's broken.
// e.g. topic_msg will be invalid the second time through
while (1){
zmq_msg_send(pubskt, &topic_msg, ZMQ_SNDMORE);

zmq_msg_init(&cmd_msg);
zmq_msg_recv(qskt, &cmd_msg, 0);
memcpy(&cmd, zmq_msg_data(&cmd_msg), sizeof(uint8_t));
zmq_msg_send(pubskt, &cmd_msg, ZMQ_SNDMORE);
zmq_msg_close(&cmd_msg);

fprintf(stdout, "received cmd %u\n", cmd);

zmq_msg_init(&nb_msg);
zmq_msg_recv(qskt, &nb_msg, 0);
memcpy(&nb, zmq_msg_data(&nb_msg), sizeof(uint32_t));
zmq_msg_send(pubskt, &nb_msg, 0);
zmq_msg_close(&nb_msg);

fprintf(stdout, "received nb %u\n", nb);

zmq_msg_init_size(&resp_msg, sizeof(uint8_t));
memset(zmq_msg_data(&resp_msg), 0, sizeof(uint8_t));
zmq_msg_send(qskt, &resp_msg, 0);
zmq_msg_close(&resp_msg);

}
return NULL;
}