[zeromq-dev] questions about sub/pub socket

Martin Sustrik sustrik at 250bpm.com
Tue Feb 2 09:42:24 CET 2010


Guo, Yanchao wrote:
> 
> Hi Martin:
> 
>  From my experient, I found that if I setup up socket in this way:
> 
> m_Context = new context_t(1,1);
> m_Socket = new socket_t(*m_Context, ZMQ_PUB);
> m_Socket->connect(port);
> 
> and then send message through this socket, then the message will be 
> queued in the socket, in a sense that if the SUB socket (which binds to 
> the port) starts later then this PUB socket, the SUB socket is able to 
> receive all the historical data.
> 
> This behavior is different from a PUB socket which bind to a port, in 
> that case the is no historical data kept.
> 
> Is it possible to make the PUB/connecting socket not caching the data?

I assume you are trying to ensure that the messages are stored in 
publisher when your subscriber disconnects for a while, right?

If so, set ZMQ_IDENTITY option on your subscriber socket. That way the 
publisher will know that subsequent TCP connections belong to the same 
peer application. It'll store messages during the time the application 
is disconnected and send them once it gets back online.

> Also, is there a onInit method to notify the server of newly established 
> connection?

No.

Martin



More information about the zeromq-dev mailing list