gpt4 book ai didi

python - 使用 Rabbitmq 和 Python 进行 Stomp 广播

转载 作者:行者123 更新时间:2023-11-28 21:30:54 25 4
gpt4 key购买 nike

我试图将系统从使用病态转移到rabbitmq,但我似乎无法获得默认提供的相同广播行为病态。我所说的广播是指当一条消息添加到队列中时,每个消费者都会收到它。对于rabbit,当添加消息时,它们会以循环方式分发给每个监听器。

谁能告诉我如何实现同样的消息分发?

下面使用的stomp库是http://code.google.com/p/stomppy/

如果无法使用 stomp,即使是 amqplib 示例也确实有帮助。

我的代码目前看起来像这样

消费者

import stomp

class MyListener(object):
def on_error(self, headers, message):
print 'recieved an error %s' % message

def on_message(self, headers, message):
print 'recieved a message %s' % message

conn = stomp.Connection([('0.0.0.0', 61613), ('127.0.0.1', 61613)], 'user', 'password')
conn.set_listener('', MyListener())
conn.start()
conn.connect(username="user", password="password")
headers = {}

conn.subscribe(destination='/topic/demoqueue', ack='auto')

while True:
pass
conn.disconnect()

发件人看起来像这样

import stomp

class MyListener(object):
def on_error(self, headers, message):
print 'recieved an error %s' % message

def on_message(self, headers, message):
print 'recieved a message %s' % message

conn = stomp.Connection([('0.0.0.0', 61613), ('127.0.0.1', 61613)], 'user', 'password')
conn.set_listener('', MyListener())
conn.start()
conn.connect(username="user", password="password")
headers = {}

conn.subscribe(destination='/topic/demotopic', ack='auto')

while True:
pass
conn.disconnect()

最佳答案

显然你不能直接使用STOMP;有一个mailing list thread这显示了使用 stomp 进行广播时必须跳过的所有环节(它涉及一些较低级别的 AMPQ 内容)。

关于python - 使用 Rabbitmq 和 Python 进行 Stomp 广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/981291/

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