使用 pecl-amqp 防止在 get() 上确认消息

发布于 2024-11-14 21:57:59 字数 236 浏览 3 评论 0原文

我正在尝试将 pecl-amqp 用于我的项目。但我在 ACK 过程中遇到了困难。我需要手动确认从队列中收到的每条消息,但在检索消息时,这些消息似乎会自动确认。

我已将队列设置为 AMQP_NOACK 并使用 AMQPQueue->get(AMQP_NOACK) 但似乎没有任何影响,消息仍然从队列中删除,而无需我发送 AMQPQueue->ack()。

如果有人对 pecl-amqp 有任何经验,我将不胜感激。

I'm attempting to use pecl-amqp for a project of mine. I'm having difficulties though with the ACK process. I need to manually ACK each message I receive off a queue, but the messages appear to be auto-ACKing when the message is retrieved.

I've set my queue to AMQP_NOACK and am using AMQPQueue->get(AMQP_NOACK) but none of it seems to have any affect, the messages are still removed from the queue without me sending AMQPQueue->ack().

If anyone has any experience with the pecl-amqp I would appreciate the help.

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

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

发布评论

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

评论(2

还给你自由 2024-11-21 21:57:59

我也遇到了同样的问题,但已经设法使用 Consumer 方法让确认机制正常工作。使用rabbitmqctl列出队列中的条目似乎工作正常,尽管我似乎以与发送消息的顺序不同的顺序将消息从队列中取出——这会破坏队列的对象。我的代码如下:

// Create the queue to be:
//      AMQP_DURABLE - messages will withstand a broker restart (i.e. they are written to disk).
//      AMQP_NOACK - when consumed messages will not be marked as delivered until an explicit ACK is received.
$q->declare($queueName, AMQP_DURABLE | AMQP_NOACK );

// Bind it on the exchange to routing key.
$q->bind($exchangeName, $routingKey);

// Set the options for our consumption of the messages:
//  Get a minimum of 0 msg.
//  Get a maximum of 1 msg.
//  Don't ACK the message on consumption i.e. explicitly acknoledge later.
$options = array(
 'min' => 0,
 'max' => 1,
 'ack' => false
);
// Get the messages
$results_array = $q->consume($options);

// show the message
print_r($results_array);
$delivery_tag =  $results_array[0]['delivery_tag'];
echo 'delivery_tag: [' . $delivery_tag . "].\r\n";

// Acknowledge receipt of the message.
$q->ack($delivery_tag);

I have been having the same problem but have managed to get the acknowledge mechanism to work using the consume method. Using rabbitmqctl to list the entries in the queue it appears to work OK, though I seems to be getting the messages off the queue in a different order to that in which they were sent - which kind of defeats the object of a queue. My code is as follows:

// Create the queue to be:
//      AMQP_DURABLE - messages will withstand a broker restart (i.e. they are written to disk).
//      AMQP_NOACK - when consumed messages will not be marked as delivered until an explicit ACK is received.
$q->declare($queueName, AMQP_DURABLE | AMQP_NOACK );

// Bind it on the exchange to routing key.
$q->bind($exchangeName, $routingKey);

// Set the options for our consumption of the messages:
//  Get a minimum of 0 msg.
//  Get a maximum of 1 msg.
//  Don't ACK the message on consumption i.e. explicitly acknoledge later.
$options = array(
 'min' => 0,
 'max' => 1,
 'ack' => false
);
// Get the messages
$results_array = $q->consume($options);

// show the message
print_r($results_array);
$delivery_tag =  $results_array[0]['delivery_tag'];
echo 'delivery_tag: [' . $delivery_tag . "].\r\n";

// Acknowledge receipt of the message.
$q->ack($delivery_tag);
糖粟与秋泊 2024-11-21 21:57:59

作为参考,AMQP 扩展未正确支持 AMQP_NOACK。你可以让它做你想做的事,但它并不漂亮。我现在正在努力解决这个问题。仅供参考,AMQP_NOACK 意味着您稍后不必返回确认消息,即服务器将消息发送到客户端后,服务器会将消息标记为已确认。围绕这个问题有些困惑,所以我想澄清一下。

For reference, the AMQP extension did not support the AMQP_NOACK correctly. You can get it to do what you want, but it isnt pretty. I am working on fixing that now. FYI, AMQP_NOACK means that you will not have to come back to acknowledge the message later, i.e. as soon as the server sends the message to the client, the server marks the message as ack'ed. There has been some confusion around this, so I wanted to clarify.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文