问题描述
我是zeromq的新手.最近,我对zeromq的pub/sub进行了一些测试,但我不知道如何通过在ZeroMQ中使用XPUB和XSUB来实现带有代理的Pub-Sub网络.希望您的帮助,非常感谢.
I am a newcomer to zeromq. Recently I did some tests on pub/sub of zeromq, and I don't konw how to implement Pub-Sub Network with a Proxy by using XPUB and XSUB in ZeroMQ. Hope your help, thank you very much .
推荐答案
代理:
int main (int argc, char *argv[])
{
zmq::context_t context(1);
zmq::socket_t frontend (context, ZMQ_XSUB);
....//set hwm
frontend.bind("tcp://*:5559");
zmq::socket_t backend (context, ZMQ_XPUB);
....//set hwm
zmq_bind (backend, "tcp://*:5560");
zmq_proxy (frontend, backend, NULL);
return 0;
}
我丢失消息的原因是我应该在绑定或连接之前先调用setsockopt.
The reason I lost message is that I should have called setsockopt before bind or connect.
有关setsockopt的信息,请参见0MQ API文档:
Refer to 0MQ API documentation for setsockopt:
警告:除ZMQ_SUBSCRIBE,ZMQ_UNSUBSCRIBE和ZMQ_LINGER以外,所有选项仅对随后的套接字绑定/连接生效.
Caution: All options, with the exception of ZMQ_SUBSCRIBE, ZMQ_UNSUBSCRIBE and ZMQ_LINGER, only take effect for subsequent socket bind/connects.
这篇关于如何通过在ZeroMQ(C ++)中使用XPUB和XSUB来实现具有代理的Pub-Sub网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!