Reputation: 11
I am new to zeromq , I modify the zeromq example a bit to test the behavior of pub-sub mode, the subscriber subscribes two topics "ABC" and "ABD", everything goes right, but when I restart the publisher, only "ABD" is received in subscriber side. Why?
sub
#include "zhelpers.hpp"
int main ()
{
// Prepare our context and subscriber
zmq::context_t context(1);
zmq::socket_t subscriber (context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5563");
subscriber.setsockopt( ZMQ_SUBSCRIBE, "ABC", 3);
subscriber.setsockopt( ZMQ_SUBSCRIBE, "ABD", 3);
while (1) {
// Read envelope with address
std::string address = s_recv (subscriber);
// Read message contents
std::string contents = s_recv (subscriber);
std::cout << "[" << address << "] " << contents << std::endl;
}
return 0;
}
pub
#include "zhelpers.hpp"
int main ()
{
// Prepare our context and publisher
zmq::context_t context(1);
zmq::socket_t publisher(context, ZMQ_PUB);
publisher.bind("tcp://*:5563");
while (1)
{
// Write two messages, each with an envelope and content
s_sendmore (publisher, "ABC");
s_send (publisher, "We don't want to see this");
s_sendmore (publisher, "ABD");
s_send (publisher, "We would like to see this");
sleep (1);
}
return 0;
}
output
[ABC] We don't want to see this
[ABD] We would like to see this
[ABC] We don't want to see this
[ABD] We would like to see this
[ABC] We don't want to see this
[ABD] We would like to see this
//kill and restart publisher
[ABD] We would like to see this
[ABD] We would like to see this
[ABD] We would like to see this
[ABD] We would like to see this
[ABD] We would like to see this
Upvotes: 1
Views: 558
Reputation: 11
I don't know if you solved this problem but I was facing this situation too. It was an issue with ZMQ, which is actually solved in version 4.0.4 (see this thread).
Regards.
Upvotes: 1