Skip to content
This repository

Can not set 'x-message-ttl' in arguments in queue_options #80

Open
phillpafford opened this Issue January 16, 2013 · 9 comments

4 participants

Phill Pafford Sven Loth Alvaro Videla Gaetano Giunta
Phill Pafford

Following the example here:

queue_options: {name: 'upload-picture', arguments: {'x-ha-policy': ['S', 'all']}}

I'm trying to do:

queue_options: {name: 'upload-picture', arguments: {'x-message-ttl': 3600000}}

as I'm trying to set the message ttl for one hour

Phill Pafford

work around ( hack ) was to add an additional parameter for the message properties and use the AMQP expiration setting. So in the producer I added this

Original:

public function publish($msgBody, $routingKey = '')
{
$this->setupProducer();

    $msg = new AMQPMessage($msgBody, array('content_type' => 'text/plain', 'delivery_mode' => 2));
    $this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
}

Hack:

public function publish($msgBody, $routingKey = '', $msgProperties = array())
{
$this->setupProducer();

    $msg = new AMQPMessage($msgBody, array_merge(array('content_type' => 'text/plain', 'delivery_mode' => 2), $msgProperties));
    $this->ch->basic_publish($msg, $this->exchangeOptions['name'], $routingKey);
}

Then call like this:

$this->exchangeProducer->publish(json_encode($message),'', array('expiration' => '3600000'));

Sven Loth
slot commented April 25, 2013

Right syntax, which works for me:

queue_options: {name: 'upload-picture', arguments: {'x-message-ttl': ['I', 3600000]}}

Phill Pafford

@slot can you point me to the documentation on this? I thought I had tried that syntax but maybe I had an error

Sven Loth
slot commented April 26, 2013

Well as I said, it works for me. It's not properly documented but the example points you in the right direction:

queue_options: {name: 'upload-picture', arguments: {'x-ha-policy': ['S', 'all']}}

where 'S' is the datatype of the argument value.

Argument data is being type-checked and processed in \PhpAmqpLib\Wire\AMQPWriter in the write_table() method.

Alvaro Videla
Owner

Would any of you mind documenting this in the README?

Sven Loth
slot commented April 26, 2013

I will do it.

Sven Loth
slot commented April 26, 2013

Done, in #109

Phill Pafford

@slot The suggested syntax works on the queue level, I'm looking to add the x-message-ttl on the message level. So not all messages in the queue will have a expiration. The added documentation was needed but the suggested syntax does not work on a message level expiration but does for the queue.

Looking to implement the message options AMQP provides but with RabbitMQ

https://github.com/videlalvaro/php-amqplib/blob/master/PhpAmqpLib/Message/AMQPMessage.php

Gaetano Giunta

+1 for allowing to set a pet-ttl message, if it is supported by the protocol. The proposed hack is basically a 2-liner...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.