How do I cleanly shutdown a consumer

1,284 views
Skip to first unread message

Christoph

unread,
Jul 10, 2012, 11:44:12 AM7/10/12
to masstrans...@googlegroups.com
Hi everyone,

If looked for an answer in the documentation, but I didn't find anything. If this is already documented, please give me a hint.

How would you cleanly shutdown a consumer? 
This means, it will not accept any new messages but still continue to process the ones it already received. After the last message was processed successful or fails, the worker could stop (this is not the problem).
My problem is, I don't know how to tell MT to stop with receiving messages. 

Any hints on this?

Thanks

Dru Sellers

unread,
Jul 10, 2012, 12:37:40 PM7/10/12
to masstrans...@googlegroups.com
do you want to shut down one consumer or the bus?

-d

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/masstransit-discuss/-/jkuPRgLqjwAJ.
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-US.

Chris Patterson

unread,
Jul 10, 2012, 1:30:29 PM7/10/12
to masstrans...@googlegroups.com
You need to shut down the bus, by calling Dispose() on the IServiceBus interface. This will stop the threads, allowing any executing consumers to complete, and cleanly exit.

On Tue, Jul 10, 2012 at 10:44 AM, Christoph <lang...@gmail.com> wrote:

--

Dru Sellers

unread,
Jul 10, 2012, 1:41:17 PM7/10/12
to masstrans...@googlegroups.com
Will Dispose block until they are all done?

-d

Travis Smith

unread,
Jul 10, 2012, 1:44:24 PM7/10/12
to masstrans...@googlegroups.com
It does. Though I don't recall if there's a timeout on how long we
will block before releasing.

-Travis

Christoph

unread,
Jul 11, 2012, 3:57:05 AM7/11/12
to masstrans...@googlegroups.com
What will happen if some error occurs and the bus is already shut down? Is the regarding Fault<T> still sent?

I have to stop the processing of new messages during the shutdown phase of a windows service. The service should wait as long as there are messages in processing, but stop to process new ones.

Chris Patterson

unread,
Jul 11, 2012, 7:59:05 AM7/11/12
to masstrans...@googlegroups.com
If you are wanting to "drain" the queues before exiting, that's not something that is available. In a distributed system, this could mean the service never exists as events and commands continue to be added to the queues by other services.

On Wed, Jul 11, 2012 at 2:57 AM, Christoph <lang...@gmail.com> wrote:
What will happen if some error occurs and the bus is already shut down? Is the regarding Fault<T> still sent?

I have to stop the processing of new messages during the shutdown phase of a windows service. The service should wait as long as there are messages in processing, but stop to process new ones.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.

Christoph

unread,
Jul 11, 2012, 8:15:34 AM7/11/12
to masstrans...@googlegroups.com
If you are wanting to "drain" the queues before exiting, that's not something that is available. In a distributed system, this could mean the service never exists as events and commands continue to be added to the queues by other services.

That is true and not the required behavior. I mean the consumer should finish the processing of the messages it already _has_ received. It should not receive _new_ ones.
I now know that for this I have to dispose the bus. 

But in the case that some of the consumers receive an error during processing and the bus is disposed, I assume the Fault<T> message couldn't be sent anymore. Is this correct?

Travis Smith

unread,
Jul 11, 2012, 8:42:20 AM7/11/12
to masstrans...@googlegroups.com
>
> But in the case that some of the consumers receive an error during
> processing and the bus is disposed, I assume the Fault<T> message couldn't
> be sent anymore. Is this correct?

The bus is not completely disposed until the consumer finishes
processing. This should still succeed as desired.

Chris Patterson

unread,
Jul 11, 2012, 11:45:29 AM7/11/12
to masstrans...@googlegroups.com
Faults will be sent just fine, the consumers already handling messages will complete and the bus is not actually disposed until all of the consumers are completed.

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.

Christoph

unread,
Jul 11, 2012, 12:20:56 PM7/11/12
to masstrans...@googlegroups.com
Great. That is exactly what I need. Thanks a lot!
Reply all
Reply to author
Forward
0 new messages