RabbitMQ message TTL

617 views
Skip to first unread message

Fawad Halim

unread,
Apr 13, 2012, 11:11:30 PM4/13/12
to masstrans...@googlegroups.com
Hi,
  I have a subscriber that's is connected to the bus very infrequently and does not have to receive messages when offline. I'd like to not have its queue fill up with messages while it's offline. My first inclination was to set message expiry when publishing, but that had the downside of the publisher knowing that the subscriber will not be interested in the message after a while. Furthermore, it seems that RabbitMQ does not actually do anything with the message expiration header and the message happily gets delivered to the subscriber long after it was supposed to have expired.

RabbitMQ does support per-queue TTL as described at http://www.rabbitmq.com/extensions.html#queue-ttl and I was able to patch the MassTransit RabbitMQ transport to support queue creation with the TTL quite easily. 

Does the per-queue TTL approach sound sensible or is there a better way to accomplish this that I have overlooked?

Regards
-fawad

Chris Patterson

unread,
Apr 13, 2012, 11:17:15 PM4/13/12
to masstrans...@googlegroups.com
Just use .Transient() on the subscription call and it will remove the binding when the subscriber is not running.

--
Chris Patterson

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-dis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

Fawad Halim

unread,
Apr 14, 2012, 5:39:57 PM4/14/12
to masstrans...@googlegroups.com
Hi,
  Thanks for the pointer. It seems that I would have to have an instance of the ServiceBusConfigurator to be able to get a SubscriptionConfigurator that'd allow me to call Transient(). My handlers are being wired using bus.SubscribeHandler. Would it be possible to wire up the transient handler from a bus instance?

-fawad

Chris Patterson

unread,
Apr 15, 2012, 4:59:49 PM4/15/12
to masstrans...@googlegroups.com
Yes, when you call SubscriberHandler<T>, a delegate UnsubscribeAction is returned. Don't call it, and your subscription will not be removed.

Fawad Halim

unread,
Apr 15, 2012, 6:41:41 PM4/15/12
to masstrans...@googlegroups.com

Ah, thanks! Totally didn't make the connection between the UnsubscribeAction with the ability to unsubscribe when done.

Do you think the queue TTL approach might still be useful in case the subscription is not properly disposed?

Regards

-fawad

Chris Patterson

unread,
Apr 15, 2012, 9:24:56 PM4/15/12
to masstrans...@googlegroups.com
Up to you if you think that makes sense, might be nice to overload the endpoint configuration somehow...

Fawad Halim

unread,
Apr 16, 2012, 12:09:23 PM4/16/12
to masstrans...@googlegroups.com
Seems that the queue is being created inside RabbitMqEndpointManagement, making it pretty tedious to override its behavior.  I ended up the queue setup manually before spinning up the MassTransit bus like so: https://gist.github.com/2399679

Doing the setup manually seemed a bit janky to me, though. It seemed a lot simpler to add an argument to the RabbitMQ endpoint URL that allowed setting up the TTL. 


Regards
-fawad

Fawad Halim

unread,
Apr 16, 2012, 12:43:20 PM4/16/12
to masstrans...@googlegroups.com
The creating the queue before bus startup does not seem to work correctly; the exchange for the endpoint does not get bound to it. I suspect it's because the queue definition differs from the one being declared from within MT.

-fawad

Fawad Halim

unread,
Apr 18, 2012, 3:58:56 PM4/18/12
to masstrans...@googlegroups.com
So is my only option to set the TTL on the queue to implement a separate transport factory that'd eventually return an IRabbitMqEndpointAddress with the correct QueueArguments? The change to have the endpointaddress return the TTL queue argument was pretty straightforward to implement, but I can't find a way to just swap out RabbitMqEndpointAddress with my own implementation.

Regards
-fawad

Chris Patterson

unread,
Apr 18, 2012, 5:15:52 PM4/18/12
to masstrans...@googlegroups.com
That seems like a good way to handle it, using an argument on the URI.

On Mon, Apr 16, 2012 at 11:09 AM, Fawad Halim <fa...@fawad.net> wrote:

Dru Sellers

unread,
Apr 18, 2012, 5:16:59 PM4/18/12
to masstrans...@googlegroups.com
I am going to push up a branch here in a moment that has that done.

-d

Dru Sellers

unread,
Apr 18, 2012, 5:21:33 PM4/18/12
to masstrans...@googlegroups.com
Ok, the pull request is open.


-d

Hami @ Leica

unread,
Oct 2, 2014, 7:18:27 PM10/2/14
to masstrans...@googlegroups.com, Qerim Shahini
Hi Dru,

How do you get at the SetTtl(...) method when initializing the bus?

-d

-d


To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/masstransit-discuss?hl=en.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To post to this group, send email to masstrans...@googlegroups.com.
To unsubscribe from this group, send email to masstransit-discuss+unsub...@googlegroups.com.

Dru Sellers

unread,
Oct 2, 2014, 10:47:42 PM10/2/14
to masstrans...@googlegroups.com, Qerim Shahini
most of the rabbit mq stuff is in extension methods, do you have the rabbit mq namespace?

-d

To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.

To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
Oct 3, 2014, 11:26:50 AM10/3/14
to masstrans...@googlegroups.com
You add ttl to the query string to set it...

rabbitmq://localhost/vhost/queue?ttl=timeInMs

This is passed straight through to the queue creation as x-message-ttl

Reply all
Reply to author
Forward
0 new messages