Using Reusable ZeroMQ C Helpers

Now it’s really easy to throw data around using the 0MQ helpers written up before!

Subscribe


void SubscribeCallback(uint8_t *buf, int size)
{
//do whatever with the payload received
}
//set up the subscribe thread
SubscribeZeroMQDataThreadArgs *subscribeThread = StartSubscribe(zmqContext, "tcp://hostname:port", "topic", SubscribeCallback, "LogCategory");
//shutdown the subscribe thread later
StopSubscribe(subscribeThread);

Request Reply


static RequestReplyZeroMQReply* RequestReplyCallback(const char *request, const void *argument, const uint8_t *data, const int size)
{
RequestReplyZeroMQReply *reply = malloc(sizeof(RequestReplyZeroMQReply));
someData_t *someData;
int len = get_some_data_to_return(&someData, data, size);
reply->data = someData;
reply->size = len;
return reply;
}
//set up the request reply thread
//NULL could be a pointer to a variable you'd like passed to the callback
RequestReplyZeroMQThreadArgs* thread = StartRequestReply(zmqContext, "tcp://hostname:port", RequestReplyCallback, NULL, "logCategory");
StopRequestReply(thread);

Forwarding


ForwardZeroMQDataThreadArgs *forwardThread = StartForward(context, "tcp://forwardTransport", "logCategory", 2, "ipc://someSubTransport", "tcp://anotherSubTransport");
StopForward(forwardThread);

Posted in C, Messaging, ZeroMQ

Leave a comment