Networking Reference
In-Depth Information
The socket options are set with the zmq_setsockopt(3) function. It takes
four parameters:
• Socket
• Option name
• Option value
• Length of the option
This can be made clear by the following line of code:
int zmq_setsockopt (void *socket, int option_name, const void *option_
value, size_t option_len);
ZMQ_SUBSCRIBE establishes a new message on the ZMQ_SUB socket. If the
option_value argument is not empty, we are subscribed to all messages
that start with option_value . You could attach multiple filters to a one
ZMQ_SUB socket.
ZMQ_UNSUBSCRIBE removes a message on the ZMQ_SUB socket. It removes only one
message even if there are multiple filters.
An important thing we need to note about the publisher-subscriber sockets is that
we do not know when the subscriber starts to receive messages. In this case, it is a
good idea to start the subscriber and then to start the publisher. This is because the
subscriber always misses the first message as connecting to the publisher takes time
and the publisher may already be sending a message.
However, we will talk about how to synchronize the publisher and the subscribers
so we do not have to send any messages unless the subscribers are really connected.
Notes on the publisher-subscriber pattern
The key points to be noted about the publisher-subscriber pattern are as follows:
• Messages are queued up on the publisher's side if you are using TCP and the
subscriber is too slow to receive messages. We will show you how to protect
the application against this.
Search MirCeyron ::

Custom Search