在两个 RabbitMQ 队列中发布消息,而不是一个(使用 py-amqp)
我使用 py-amqp 和 Flopsy 模块。我编写了一个将消息发送到 RabbitMQ 服务器的发布者,并且我希望能够将其发送到指定的队列。在 Flopsy 模块上这是不可能的,所以我对其进行了调整,添加了一个参数和一行来在 Publisher 对象的 _init__ 方法上声明队列
def __init__(self, routing_key=DEFAULT_ROUTING_KEY,
exchange=DEFAULT_EXCHANGE, connection=None,
delivery_mode=DEFAULT_DELIVERY_MODE, queue=DEFAULT_QUEUE):
self.connection = connection or Connection()
self.channel = self.connection.connection.channel()
self.channel.queue_declare(queue) # ADDED TO SET UP QUEUE
self.exchange = exchange
self.routing_key = routing_key
self.delivery_mode = delivery_mode
通道对象是 py-amqplib 库的一部分
我遇到的问题是,即使它将消息发送到指定队列,它也会将消息发送到默认队列。在这个系统中,我们希望发送大量消息,我们不想给系统造成无用的重复......我尝试调试代码并进入 py-amqplib 库,但我无法找出任何错误或缺少的步骤。另外,我无法在代码之外找到 py-amqplib 的任何文档。
关于为什么会发生这种情况以及如何纠正它有什么想法吗?
I've got this strange problem using py-amqp and the Flopsy module. I have written a publisher that sends messages to a RabbitMQ server, and I wanted to be able to send it to a specified queue. On the Flopsy module that is not possible, so I tweaked it adding a parameter and a line to declare the queue on the _init__ method of the Publisher object
def __init__(self, routing_key=DEFAULT_ROUTING_KEY,
exchange=DEFAULT_EXCHANGE, connection=None,
delivery_mode=DEFAULT_DELIVERY_MODE, queue=DEFAULT_QUEUE):
self.connection = connection or Connection()
self.channel = self.connection.connection.channel()
self.channel.queue_declare(queue) # ADDED TO SET UP QUEUE
self.exchange = exchange
self.routing_key = routing_key
self.delivery_mode = delivery_mode
The channel object is part of the py-amqplib library
The problem I've got it's that, even if it's sending the messages to the specified queue, it's ALSO sending the messages to the default queue. AS in this system we expect to send quite a lot of messages, we don't want to stress the system making useless duplicates... I've tried to debug the code and go inside the py-amqplib library, but I'm not able figure out any error or lacking step. Also, I'm not able to find any documentation form py-amqplib outside the code.
Any ideas on why is this happening and how to correct it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我已经明白了。除非其他人有更好的主意。我已检查关于 AMQP 的教程 我假设发布者应该知道队列,但事实并非如此,您需要将消息发送到交换器,并且消费者会声明该队列与交换器相关。正如您在教程中看到的,这允许发送和接收不同的选项。
因此,我一直在包含有关发布者和消费者的交换信息,而不是使用对
queue_declare
的调用,而且它似乎工作得很好。OK, I've think I've got it. unless anybody else have a better idea. I've check this tutorial on AMQP I was assuming that the publisher should know the queue, but that's not the case, you need to send the message to a exchange, and the consumer will declare that the queue is related to the exchange. That allow different options on sending and receiving, as you can see on the tutorial.
So, I've been including the exchange information on both the publisher and the consumer, not making use of the call to
queue_declare
and it appears to be working just fine.