[rabbitmq-discuss] Message TTL/Expiration

Bryan Murphy bmurphy1976 at gmail.com
Thu Jun 18 20:16:04 BST 2009

Hey guys, I'm new to RabbitMQ and am having trouble finding the answer to
this question on Google, so please forgive me if this is old hat.
I'm trying to setup a request/response queue with a TTL on the request
messages.  My client is only going wait 500ms for a response.  If the client
does not get a response in 500ms it's going to bail.  Because of this,
there's no reason for the server to handle messages that have been in the
queue for longer than 500ms.

I've setup a simple test case using SimpleRpcClient and SimpleRpcServer.
 Everything works except message expiration.  All requests sent to the queue
are processed by the server code, regardless of how long they sat in the
queue.  I could, of course, add a timestamp to my message and handle filter
them manually, but I was hoping the RabbitMQ infrastructure could do this
for me.

Here's the client code (C#):

var connectionFactory = new ConnectionFactory();

using (var connection = connectionFactory.CreateConnection(""))
using (var model = connection.CreateModel())
model.ExchangeDeclare("TestExchange", ExchangeType.Direct);
model.QueueBind("TestQueue", "TestExchange", "TestRoute", false, null);

var client = new SimpleRpcClient(model, "TestExchange", "TestQueue",

client.TimeoutMilliseconds = 500;

var request = Guid.NewGuid().ToString("N");
var requestData = Encoding.UTF32.GetBytes(request);

var requestProperties = model.CreateBasicProperties();
requestProperties.Expiration = "1000";

var responseData = client.Call(requestProperties, requestData);

if (responseData == null)
Console.Out.WriteLine("{0}: Timed Out", request);
Console.Out.WriteLine("{0}: {1}", request,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20090618/0f33320d/attachment.htm 

More information about the rabbitmq-discuss mailing list