我试着给系统使用病态到RabbitMQ的移动,但我似乎无法得到相同的广播病态行为默认情况下提供。通过广播我的意思是,当消息被添加到队列中,每一个消费者临危它。用兔,当添加的消息它们分布循环赛样式的每一个监听器。

谁能告诉我如何实现同种报文分发?

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

如果不能够做到与跺脚,甚至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()
有帮助吗?

解决方案 2

我终于想通了如何通过为每个“recieving组”交换做到这一点,林不知道还有兔子怎么会做成千上万的交流,所以你可能要在生产中尝试之前推测测试这个沉重

在发送代码:

conn.send(str(i), exchange=exchange, destination='')

是必需的空白目的地,我所关心的是发送给该交换

要收到

import stomp
import sys
from amqplib import client_0_8 as amqp
#read in the exchange name so I can set up multiple recievers for different exchanges to tset
exchange = sys.argv[1]
conn = amqp.Connection(host="localhost:5672", userid="username", password="password",
 virtual_host="/", insist=False)

chan = conn.channel()

chan.access_request('/', active=True, write=True, read=True)

#declare my exchange
chan.exchange_declare(exchange, 'topic')
#not passing a queue name means I get a new unique one back
qname,_,_ = chan.queue_declare()
#bind the queue to the exchange
chan.queue_bind(qname, exchange=exchange)

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)], 'browser', 'browser')
conn.set_listener('', MyListener())
conn.start()
conn.connect(username="username", password="password")
headers = {}

#subscribe to the queue
conn.subscribe(destination=qname, ack='auto')

while True:
    pass
conn.disconnect()

其他提示

显然,你不能做直接与STOMP;有一个邮件列表线程显示全部篮球,你必须通过跳跃来获得广播与STOMP工作(它涉及到一些较低级别AMPQ东西)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top