Search code examples
c#msmqrebus

Handle Rebus MSMQ Queue deletion


I am using MSMQ transport in our rebus implementation. Below is the code for starting rebus service:

BuiltinHandlerActivator handlerActivator;
this.handlerActivator.Handle<TransportMessage>    
(this.HandleTransportMessageAsync);

 var bus = Configure.With(this.handlerActivator)
           .Transport(t => t.UseMsmq(this.SenderName))
           .Routing(r => r.TypeBased().AddEndpointMappingsFromAppConfig())
           .Start();  

I want to handle exception/errors in case some one accidentally deletes message queues using snoop/compmgmt.msc.

When I remove the MSMQ message queue manually in message queuing we receive a error with text

rebus worker queue was deleted - will not receive any more messages

.

So, want to know Is it possible in Rebus to handle this exception and supply a call back or any other way?

I noticed there is a class called MsmqTransport in Rebus.MSMQ namespace which expose method AddQueueCallback to supply similar callback. Since I am newbie to Rebus/MSMQ I am not able to figure out how to use this. Any support would be helpful.


Solution

  • If you delete a Rebus endpoint's input queue or error queue while it is running, there is no help getting them back.

    Rebus could handle this situation of course (in its transport implementation, and, in your case – as you have correctly figured out – in the MsmqTransport class) – but I (and contributors of other transports) must have thought at some point that it was not necessary to do that, probably because queues suddenly disappearing at runtime would be a pretty uncommon scenario.

    In a way, I would NOT want my endpoint to just continue working if its input queue was accidentally deleted – I think I would prefer ERRORs in the logs and red lights blinking, because that situation would be a pretty big disaster in production.

    I suggest you do not delete the queues while the system is running. If you accidentally delete a queue when messing around with Rebus Snoop on your machine, you can just restart your endpoint and then everything will be back to normal.


    btw the AddQueueCallback method was added such that it would be possible to customize user rights on automatically created queues ... I guess it would be possible to do something similar for particular errors, e.g. like the "WHOA THERE'S NO QUEUE!!1" scenario. If you feel this is something that is missing, you should suggest it by creating an issue here