Open Prinkesh opened 3 years ago
#include <zmq.hpp>
#include <iostream>
#include <unistd.h>
class ZmqHandler {
public:
ZmqHandler(std::ostream& log) : myfile(log) {
// ... Your previous code ...
// Set the XPUB socket to not drop any subscriptions when a subscriber disconnects
int keepalive = 1;
frontend->setsockopt(ZMQ_XPUB_VERBOSE, &keepalive, sizeof(keepalive));
}
~ZmqHandler() {
delete publisher;
delete subscriber;
}
private:
zmq::context_t context;
zmq::socket_t* publisher;
zmq::socket_t* subscriber;
std::ostream& myfile;
};
int main() {
try {
zmq::context_t context(1);
// Socket facing clients
zmq::socket_t frontend(context, zmq::XPUB);
frontend.bind("tcp://192.168.151.8:19925");
// Socket facing services
zmq::socket_t backend(context, zmq::XSUB);
backend.bind("tcp://192.168.151.8:19926");
// Set the XPUB socket to not drop any subscriptions when a subscriber disconnects
int keepalive = 1;
frontend.setsockopt(ZMQ_XPUB_VERBOSE, &keepalive, sizeof(keepalive));
zmq::device(zmq::FORWARDER, frontend, backend);
}
catch (const std::exception& e) {
std::cout << "Error: " << e.what() << std::endl;
std::cout << "Bringing down zmq device" << std::endl;
}
return 0;
}
Issue description
Pub sub client crashes after xpub-xsub forwarder device is shutdown able to recreate when the client and server are on different machines
Steps to recreate
If we use pub-sub forwarder this issue doesn't happen. Why would this be case ? If we remove HEARTBEAT_TIMEOUT setting from publisher this issue doesn't happen.
Environment
Minimal test code / Steps to reproduce the issue
1. Client Code
def main():
if name == "main": main()
What's the expected result?