设置AMQP(RabbitMQ)的传递模式
文档说:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法让交易所继续尝试传递您的消息。
通常,消息的接收者要么自动确认消息,要么在成功处理消息后确认消息。我推荐这两个选择中的第二个。如果消息没有被确认,那么它将被重新排队,并且如果队列中有多个订阅者,那么可能会有不同的订阅者来处理它。
我的经验都是主题交换(通过让多个队列订阅相同的routing_key来实现扇出。我总是使用delivery_mode 2并且还将队列声明为持久的。
如果在发布消息之前队列不存在,那么它们将 我怀疑您的问题出在字符串
'2'
上。您是否尝试过使用数字
2
来代替?数组也是如此。成功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 number2
instead? Also it is a good idea to specify a content_type in the array as well. That would make it