期待熟悉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没有用对?
ringa_lee2017-04-17 11:32:36
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