5

How can I set the message TTL ( Not the Queue ) from either the

  • Exchange ( The exchange sends to multiple queues )
  • Message ( when publishing the message )
  • Queue ( On the queue itself but again this is the Message TTL and not the Queue TTL )

I'm running RabbitMQ 3.x, Symfony 2.1.x and the RabbitMqBundle.

What I've tried:

  • Setting the Message TTL when I make the queue itself from the RabbitMQ Admin UI

I set the message properties to 'x-message-ttl' => 3600000. In the RabbitMQ config it looks like this:

{
    "name": "blah_queue",
    "vhost": "foobar",
    "durable": true,
    "auto_delete": false,
    "arguments": {
            'x-message-ttl' => 3600000
    }
},

this is the error I get:

PRECONDITION_FAILED - inequivalent arg 'x-message-ttl'for queue

I tried setting in the config.yml ( symfony / https://github.com/videlalvaro/RabbitMqBundle / README )

this gives a bunch of errors with the AMQP library the bundle uses.

I tried modifying the AMQP library itself to allow the x-message-ttl message properties and I get an exception Error sending data.

Has anyone set the Message TTL using the RabbitMQBundle?

queue_options:    {name: 'blah_queue', arguments: {'x-message-ttl' => 3600000}}
Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
  • 1
    I believe you want to do something like this: `arguments: {'x-message-ttl' : ['I', 3600000]}' look at [this test file](https://github.com/romainneutron/php-amqplib/blob/9165f99461c3455ddc93916ad0821e99b0d19c43/demo/queue_arguments.php) for the under lying library – james_t Jan 16 '13 at 20:58

2 Answers2

1
queue_options:    {name: 'blah_queue', arguments: {'x-message-ttl' : ['I', '3600000']}}
james_t
  • 2,723
  • 1
  • 15
  • 20
  • Sorry that was one of the options I tried already, it didn't work – Phill Pafford Jan 17 '13 at 13:09
  • 1
    This works correctly for me with Rabbit 2.8 and the latest versions of both RabbitMQBundle and php-ampqlib. Haven't test with 3.x releases of Rabbit, but perhaps the option has changed? – james_t Jan 17 '13 at 16:12
  • 1
    Also, you need to delete the queue before running a consumer/producer. You cannot add this argument to a queue which does not already have it. – james_t Jan 17 '13 at 16:14
  • Tested with RabbitMQ 3.0.1. Works fine. – james_t Jan 17 '13 at 16:18
  • I hacked it to work at the message level: https://github.com/videlalvaro/RabbitMqBundle/issues/80 – Phill Pafford Jan 17 '13 at 17:46
1

I can set the queue message time to live from the rabbitmq management console like this:

  1. I'm using RabbitMQ 3.1.5 on Fedora Linux, visit this in the browser:

    http://your_rabbitmq_server.com:15672

  2. Click "Queues" tab and scroll down to where it says: "Add a new queue"

  3. Under the subsection: "Add a new queue", fill out these text boxes:

    Virtual host:             /
    Name:                     myqueue1
    Durability:               Durable
    Auto delete:              No
    Message TTL:     
    Auto expire: 
    Max length: 
    Dead letter exchange:
    Dead letter routing key: 
    
    Argument key      = x-message-ttl
    Argument value    = 3600000
    Argument datatype = number
    
  4. Click OK to save it.

Now I could consume from the queue and the message will still be there for the specified time.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335