在分布式负载管道中使用 Zeromq,我可以获得消息发送到的最后一个服务器的地址
如果我设置一个在集群中分配负载的管道,我想记录消息发送的位置。这就是我的想法(python):
import zmq
context = zmq.Context()
socket = context.socket(zmq.DOWNSTREAM)
socket.connect("tcp://127.0.0.1:5000")
socket.connect("tcp://127.0.0.1:6000")
msg = "Hello World\0"
connection_string = socket.send(msg)
# should print "Sent message to tcp://127.0.0.1:5000"
print "Sent message to", connection_string
但我找不到任何谈论这个的东西。任何帮助都值得赞赏。
If I set up a pipeline which distributes load across a cluster, I would like to log where the messages get sent. This is what I have in mind (python):
import zmq
context = zmq.Context()
socket = context.socket(zmq.DOWNSTREAM)
socket.connect("tcp://127.0.0.1:5000")
socket.connect("tcp://127.0.0.1:6000")
msg = "Hello World\0"
connection_string = socket.send(msg)
# should print "Sent message to tcp://127.0.0.1:5000"
print "Sent message to", connection_string
But I cant find anything that talks about this. Any help at all is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它认为您需要在拓扑中的某个位置使用 X(REP|REQ) 套接字来实现此目的。您可能想要检查受监控的队列设备:
http://github.com/zeromq/pyzmq/blob/master/zmq /devices.pyx
对于一般信息,也请查看此处的图表和模式说明:
http://ipython.scipy.org/doc/nightly/html/development /parallel_connections.html
另请注意,DOWNSTREAM 套接字类型现在称为 PUSH(相应的 UPSTREAM 已更改为 PULL)。
It think you'll want to use the X(REP|REQ) sockets somewhere in the topology for this. You might want to checkout the monitered queue device:
http://github.com/zeromq/pyzmq/blob/master/zmq/devices.pyx
And for general info have a look at the diagram and explanations of the patterns here too:
http://ipython.scipy.org/doc/nightly/html/development/parallel_connections.html
Also note that the DOWNSTREAM socket type is now called PUSH (and the corresponding UPSTREAM has changed to PULL).
也许您可以在回复中包含收件人的地址,然后将其记录下来?
Perhaps you could include the address of the recipient within the reply and log it then?
我的 0.02 美分...
好吧,我相信由于 ZMQ 以公平队列方式路由,所以这将是循环赛。因此,消息将按顺序发送给接收者。然而,在这种假设下编写代码并不是正确的事情,因为底层路由逻辑可能会在未来版本中发生变化。
对于 PUSH/PULL,我不确定,但是对于 REQ/REP,我猜 REP 方可以将答复发送回信封中,并将第一个字段作为其地址。这样 REQ 可以在套接字上读取两次并获取响应者地址和数据。
My 0.02 cents...
Well i believe since ZMQ routes in fair queue manner, that would be round robin. Hence messages would be sent to recepients in order. However, writing code under that assumption would not be the right thing since the underlying routing logic might change in future versions.
For PUSH/PULL, i am not sure, however for REQ/REP, i guess the REP side can send the reply back in an envolope with the first field as its address. That way the REQ can read twice on the socket and get the responder address as well as the data.