0
votes

I use zeromq sub-pub mode in my app, but I got a problem: I started sub app and subscribed the message, and then started pub app later, and the pub app will not publish any message in half hour or longer, after this, the pub app will pub messages to the sub-app, but the sub-app was blocked there without any message or some of the messages are lost.

If someone knows what's the problem? Thank you in advance.

1
Publisher:#include "stdafx.h" #include <zmq.h> int _tmain(int argc, _TCHAR* argv[]) { void* context = zmq_ctx_new(); void* server = zmq_socket(context, ZMQ_PUB); zmq_bind(server, "tcp://192.168.1.212:5555"); printf("wait for one and half hour\n"); Sleep(1000*60*60*1.5); while(1) { char buffer[256] = {0}; sprintf_s(buffer, "%s", "Hello World!"); zmq_send(server, buffer, 256, 0); printf("send: %s\n", buffer); Sleep(1000*60); } return 0; } - Kenton
Subscriber:#include "stdafx.h" #include <zmq.h> int _tmain(int argc, _TCHAR* argv[]) { void* context = zmq_ctx_new(); void* socket = zmq_socket(context, ZMQ_SUB); zmq_connect(socket, "tcp://202.101.xxx.xx:5555"); zmq_setsockopt(socket, ZMQ_SUBSCRIBE, "", 0); while(1) { char buffer[256] = {0}; zmq_recv(socket, buffer, 256, 0); printf("recv: %s\n", buffer); } return 0; } - Kenton
I think it's because I didn't set ZMQ_TCP_KEEPALIVE in my socket, am I right? - Kenton

1 Answers

0
votes

Ideally, you should start the publisher first, then the subscribers.

Also, read this section in the guide regarding scenarios where messages between PUB and SUB can get lost: http://zguide.zeromq.org/page:all#Getting-the-Message-Out

Without any additional information, or code snippets of what you're doing, it's hard to troubleshoot this issue.