设置AMQP(RabbitMQ)的传递模式

发布于 2024-11-27 06:00:51 字数 428 浏览 0 评论 0原文

文档说:

public bool AMQPExchange::publish ( string $message , string $routing_key [, int $params = 0 [, array $attributes ]] )

所以我有这个

 $this->exchange->publish(serialize($queue_message), $routing_key,AMQP_MANDATORY,array('delivery_mode' => '2'));

,我想让交换 继续尝试传递消息吗?

The docs say:

public bool AMQPExchange::publish ( string $message , string $routing_key [, int $params = 0 [, array $attributes ]] )

So I have this

 $this->exchange->publish(serialize($queue_message), $routing_key,AMQP_MANDATORY,array('delivery_mode' => '2'));

I'm trying to let the exchange KEEP TRYING to deliver the message?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑看君怀她人 2024-12-04 06:00:52

您无法让交易所继续尝试传递您的消息。

通常,消息的接收者要么自动确认消息,要么在成功处理消息后确认消息。我推荐这两个选择中的第二个。如果消息没有被确认,那么它将被重新排队,并且如果队列中有多个订阅者,那么可能会有不同的订阅者来处理它。

我的经验都是主题交换(通过让多个队列订阅相同的routing_key来实现扇出。我总是使用delivery_mode 2并且还将队列声明为持久的。

如果在发布消息之前队列不存在,那么它们将 我怀疑您的问题出在字符串 '2' 上。

您是否尝试过使用数字 2 来代替?数组也是如此。成功

$this->exchange->publish(serialize($queue_message),
            $routing_key,AMQP_MANDATORY,array('delivery_mode' => 2,
                                              'content_type' => 'text/json'));

You cannot tell the exchange to keep trying to deliver your message.

Normally, the recipient of a message will either auto-ack the message, or they will ack the message after successfully processing it. I recommend the second of these two choices. If a message is not acked then it will be requeued and if there is more than one subscriber to the queue, then it is possible that a different subscriber will process it.

My experience is all with topic exchanges (where you implement fanouts by having multiple queues that subscribe to the same routing_key. I always used delivery_mode 2 and also declared the queues as durable.

If the queue does not exist before messages are published, then they will silently disappear.

I suspect that your problem is with the string '2'. Have you tried using the number 2 instead? Also it is a good idea to specify a content_type in the array as well. That would make it

$this->exchange->publish(serialize($queue_message),
            $routing_key,AMQP_MANDATORY,array('delivery_mode' => 2,
                                              'content_type' => 'text/json'));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文