On the wire, ØMQ messages are blobs of any size, from zero upwards, that fit in memory. You do your own serialization using protobufs, msgpack, JSON, or whatever else your applications need to speak. It’s wise to choose a data representation that is portable and fast, but you can make your own decisions about trade-offs.
In memory, ØMQ messages are
zmq_msg_t structures (or classes, depending on
your language). Here are the basic ground rules for using ØMQ messages
You create and pass around
zmq_msg_t objects, not blocks of
To read a message, you use
zmq_msg_init() to create an empty message,
and then you pass that to
To write a message from new data, you use
zmq_msg_init_size() to create a message
and at the same time allocate a block of data of some size. You then
fill that data using
and pass the message to
To release (not destroy) a message, you call
zmq_msg_close(). This drops a reference,
and eventually ØMQ will destroy the message.
To access the message content, you use
zmq_msg_data(). To know how much data the
message contains, use
Do not use
zmq_msg_init_data() unless you’ve read the
manual pages and know precisely why you need these.
Here is a typical chunk of code working with messages that should be familiar if you have been paying attention. This is from the zhelpers.h file we use in all the examples:
// Receive 0MQ string from socket and convert into ...