gpt4 book ai didi

python - Pub/Sub - 订阅非 0MQ 发布者

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:10 25 4
gpt4 key购买 nike

我目前正在尝试使用 0MQ 创建代理。我想订阅一个不在 0MQ 下运行的发布者。我的意思是我有发送 XML 文件的远程发布者的地址和端口,我想获取该文件。不幸的是,我没有收到发布者的任何消息,但它发送得很好。

我正在做的是(在 Python 中):

context    = zmq.Context(1)
subscriber = context.socket(zmq.SUB)
subscriber.connect(address)
subscriber.setsockopt(zmq.SUBSCRIBE, '') # I want to subscribe any topics

同时,我有一个发布者发送接收到的消息(如果发生的话):

publisher = context.socket (zmq.PUB)
publisher.bind(publishing_address)

最后,

while True:
data = subscriber.recv()
print data
publisher.send(data)

我测试了我的代理,当我将它连接到 0MQ 发布者时它可以工作,但是当我连接到不工作的非 OMQ 发布者时。

最佳答案

恐怕这无法实现,因为ØMQ is not a neutral carrier :

A common question that newcomers to ØMQ ask (it's one I've asked myself) is, "how do I write an XYZ server in ØMQ?" For example, "how do I write an HTTP server in ØMQ?" The implication is that if we use normal sockets to carry HTTP requests and responses, we should be able to use ØMQ sockets to do the same, only much faster and better.

The answer used to be "this is not how it works". ØMQ is not a neutral carrier, it imposes a framing on the transport protocols it uses. This framing is not compatible with existing protocols, which tend to use their own framing. For example, compare an HTTP request and a ØMQ request, both over TCP/IP.

换句话说:ØMQ只能与ØMQ对话

关于python - Pub/Sub - 订阅非 0MQ 发布者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16234301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com