c++ - zeromq中的router/dealer模式在多线程下的无法收到消息?
天蓬老师
天蓬老师 2017-04-17 11:30:36
0
1
719

期待熟悉zeromq的前辈。

在zeromq的guide里,它用router/dealer模式做了一个broker

client对应ZMQ_REQ类型的zmq_socket
worker对应ZMQ_REP类型的zmq_socket
broker创建一个router和一个dealer,router接受client的消息并转发给worker,worker再把处理结果发送给dealer,dealer再转发给client.

然后我尝试把这个代码做一个变换,由多进程改为多线程,代码如下:
https://gist.github.com/ichenq/61fc280e153313e2d828

可是broker收到client的消息后,却无法发送给worker,不知道是什么原因?
或者不知道我的代码里哪个API没有用对?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
左手右手慢动作

Question and answer after 2 hours.

It is indeed a problem with my own code. The parameter ZMQ_SNDMORE passed to zmq_msg_send in the create_broker function is written as ZMQ_MORE.
Now the gist has been updated.

You can use tcp to do multi-threading. The same code can be changed to inproc to do multi-threading.

Another thing to note is that zmq socket does not have domain name resolution when binding. You can only select the IP address or * number (localhost cannot be used), but when connecting to connet, domain name resolution is required. You can No need to specify IP

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template