[rabbitmq-discuss] time to live on a durable message
watson.timothy at gmail.com
Wed Oct 16 08:52:36 BST 2013
On 15 Oct 2013, at 18:58, "PATAR, SAGAR" <sp345s at att.com> wrote:
> Is there a way we can define time to live on a message published to a durable exchange ..
Not really, because exchanges don't hold messages, only queues do.
> What happens when a message binding key doesn’t matches any binding .. does it stay in the durable exchange till the time to live is expired ..
No. When messages are unroutable, they're discarded (and possibly returned to the sender, depending on how they were published).
> Scenario 1:
> Let’s say we have a time to live of 2 hr for a message and its published to a durable exchange with no binding Key match (ex: binding key = NoMatch) … after 1 hr let’s say a client subscribes for messages with bindingKey =”NoMatch” on that exchange .. will the message be delivered to the client ??
To do this, you might create a catch all binding to a queue on which you've set a 1hr TTL and configure a dead-letter-exchange to republish if necessary.
When subscribing, consume from both the catch all queue and the queue you're actually interested in. But of course the message will be routed to both queues so you'll see it twice if it matches the 'real' binding.
You might be able to work around this with some crazy complex topology, but I doubt it. You can de-duplicate based on correlation-id, though of course this puts storage requirements onto your application.
Personally, I'd try to re-design the system to avoid this scenario, perhaps by handling unroutable messages on the sender instead, or by attaching a housekeeper to the catch all queue that republishes periodically. Bear in mind that if your "client subscribes to messages with a binding key "NoMatch" - I assume this means they create a temporary queue and bind it tot the exchange - then just having the TTL plus setting the dead letter exchange might work, though once a cycle is detected you'll loose the message iirc.
> Scenario 2:
> Let’s say we have a time to live of 2 hr for a message and its published to a durable exchange with a binding key match (ex: binding key = match) and the message will be routed to a queue and is consumed by a client .. After 1 hr If a new client subscribes for the messages with bindingKey =”match” by creating a new Queue ..will the new client get the same message
That won't work, since once a message is delivered it will be removed from the queue. You could try doing the thing above (with TTL and DLX) an use a fanout exchange to simulate this, but there are probably lots of corner cases that wont work as expected.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rabbitmq-discuss