RabbitMQ Transport, BrokerUnreachableException


(Peter) #1

Hi All,

I am using:
NSB 6.4.2
NSB.RabbitMQ 4.4.0
RabbitMQ 3.6.11

Endpoint configured as Send-only!
When I start endpoint in order to send a message and (for any reason) the broker becomes unattainable, Endpoint.Start() does not throw any Exception, error throws only after Send() invocation(BrokerUnreachableException).
After a few retries of Send(), if broker comes up I still receive an exception with the message “None of the specified endpoints were reachable”.

I have a couple of questions about this behavior:

  1. How to check if the created instance has a connection to the broker?
  2. Is there a way of configuring this kind of behavior (Automatically reconnect if the broker were unreachable at the moment of instance creation?

Thank you!


(Brandon Ording) #2

@peter

The way the that the RabbitMQ transport works is that it doesn’t attempt to open a connection for sending messages until the first time you send one.

With a regular endpoint this means that the connection for receiving messages is opened during the Endpoint.Start call since that is when the message pump is started. If the broker is unavailable, that means you’ll see an exception thrown from the Start call.

However, for a send-only endpoint, there is no message pump, so there won’t be any connection to the broker until a message is sent. That’s why you’re seeing the exception being thrown from the Send method.

We’re using a Lazy<T> to achieve this on-demand connection opening, so this does mean that if the broker isn’t available when we try to create a connection, the exception thrown will be cached for the lifetime of the endpoint, so we’ll never be able to successfully create a connection.

Currently the only way to deal with this would be to create a new send-only endpoint if you see it throw a BrokerUnreachableException.

This behavior seems less than ideal, so I’ve opened https://github.com/Particular/NServiceBus.RabbitMQ/issues/456 for us to consider making some changes to improve it.


(Peter) #3

Thank you very much for the prompt reply.


(Brandon Ording) #4

We’ve just released NServiceBus.RabbitMQ 4.4.1, which includes a fix for the problem you were seeing. The connection for sending messages is now no longer being created through a Lazy<T>. It is now created when the endpoint is started and not when the first message is sent.