使用 Rabbitmq 和 Python 进行 Stomp 广播
我试图将系统从使用病态转移到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()
Im trying to move a system from using morbid to rabbitmq, but I cannot seem to get the same broadcast behaviour morbid supplied by default. By broadcast I mean that when a message is added to the queue, every consumer recieves it. With rabbit, when a message is added they are distributed round robin style to every listener.
Can anyone tell me how to achieve the same kind of message distribution?
The stomp library used below is http://code.google.com/p/stomppy/
Failing being able to do with with stomp, even a amqplib example would really help.
My code at present looks like this
The Consumer
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()
And the sender looks like this
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然你不能直接使用 STOMP; 有一个邮件列表线程,显示了所有你必须跳过这些障碍才能让广播与 stomp 一起工作(它涉及一些较低级别的 AMPQ 内容)。
Apparently you can't do with directly with STOMP; there is a mailing list thread that shows all the hoops you have to jump through to get broadcast working with stomp (it involves some lower-level AMPQ stuff).
我终于想出了如何通过为每个“接收组”创建一个交换来做到这一点,我不确定兔子在数千个交换中的表现如何,所以
在发送代码中 在生产中尝试之前,您可能需要对其进行大量测试:
空白目的地是必需的,我关心的只是发送到该交易所
接收
I finally figured out how to do it by creating an exchange for each "recieving group", im not sure how well rabbit will do with thousands of exchanges, so you might want to figure test this heavily before trying it in production
In the sending code:
The blank destination is required, all I care about is sending to that exchange
To recieve