我试图将一个系统从使用病态到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()
发送者看起来像这样
^{pr2}$
我终于想出了如何做到这一点,通过为每个“接收组”创建一个交换,我不确定rabbit将如何处理数千个交换,所以您可能需要在投入生产前对其进行大量测试
在发送代码中:
空的目的地是必需的,我只关心发送到那个交换所
接收
^{pr2}$显然,你不能直接使用STOMP;有一个mailing list thread显示了要使用STOMP进行广播所需的所有步骤(它涉及一些较低级别的AMPQ内容)。在
相关问题 更多 >
编程相关推荐