【问题标题】:RabbitMQ: Untouching the queue expiry upon sendingRabbitMQ:发送时不触及队列到期
【发布时间】:2015-02-01 13:43:01
【问题描述】:

RabbitMQ 支持队列的过期时间(又名队列 TTL)。 As explained in RabbitMQ documentation,通过将 x-expires 参数设置为 queue_declare 方法,可以很容易地为给定队列设置到期时间。 为了发送消息,我声明了队列,然后使用basic_publish 方法推送消息。 但是,我的发送代码会“触及”队列到期时间 - 当发送消息时,到期时间会重置为其初始值(在我的示例中为 30 秒)。

这是我如何创建队列的一个简单示例:

$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();

// queueKey is given as first arg
$queueName = $argv[1];
// auto-delete the queue after x ms
$channel->queue_declare($queueName, false, true, false, false, false, 
    new AMQPTable(array("x-expires"  => 30000 )) 
);

这就是我发送消息的方式:

$channel->queue_declare($queueName, true, true, false, false, false,
    new AMQPTable(array("x-expires"  => 30000 )));  // auto-delete the queue after x ms

// mark messages as persistent 
$msg = new AMQPMessage($data, array(
    'delivery_mode' => 2
));

// pushing the message to the queue
$channel->basic_publish($msg, '', $queueName);

发送消息时有什么办法不触及过期时间吗?我希望仅在某人真正消费消息(即有消费者)而不是在发送时才触及到期时间。我的意思是,当“某人”发送消息时,我希望我的 30 秒计时器不会被重置。

谢谢!

【问题讨论】:

    标签: php rabbitmq


    【解决方案1】:

    您如何运行发布消息的脚本?

    未使用表示队列 […] 尚未重新声明

    因此,如果您每次运行生产者时都在代码中调用queue_declare,则计时器将被重置。

    您可以在单独的脚本中声明队列,然后在您的生产者上不要发出queue_declare

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 2020-03-14
      • 1970-01-01
      • 1970-01-01
      • 2021-09-26
      • 2016-08-13
      • 1970-01-01
      相关资源
      最近更新 更多