pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

RawRabbit Connection #297

Closed ma7ammad closed 6 years ago

ma7ammad commented 6 years ago

Hi,

  1. I want to first check if RawRabbit is alive when i start the app, otherwise the app should stop.
  2. If RawRabbit was connected at app-startup but failed thereafter i want to stop the app.

I have searched the docs but could not find much. Is there anyway to check whether RawRabbit is connecting/running?

Thanks.

pardahlman commented 6 years ago

Hello, @ma7ammad - thanks for reaching out. I have a few follow up questions for you:

ma7ammad commented 6 years ago

@pardahlman ,

  1. I am using RawRabbit v.2.x.
  2. "check if RawRabbit is alive": Example: at the moment RawRabbit is run from a docker container. Sometimes RawRabbit is down (container is stopped) and when a RawRabbit-call is made a ConnectFailureException is thrown.

I am looking for a way, to check at the startup of the app and during the the time that the app is running, to tell if RawRabbit stops (at any moment) so i can stop the app.

pardahlman commented 6 years ago

Hello again. Do you mean that the RabbitMQ broker is hosted in a docker container?

If you want to solve the problem of connect retry when the broker is down, then perhaps the Polly enricher might solve this issue, especially as it has support for declaring retry policies for the channel factory.

ma7ammad commented 6 years ago

Hi, No it is not that. I am not looking to solve a connection problem but i am looking for a way to tell if there is a problem -regardless of the cause- which is bringing RawRabbit down. The app which is using RawRabbit should not work if RawRabbit is down; it should be stopped (Environment.Exit(1)).

pardahlman commented 6 years ago

I think what confuses me is what you mean with "RawRabbit" in this context:

The app which is using RawRabbit should not work if RawRabbit is down

Do you mean that the client application using RawRabbit should not work if the RabbitMQ broker is not responding? If that's the case, you could try to setup a subscription or publish a message and see if you get an exception.

Another option would be to replace the default IChannelPoolFactory with the StaticChannelPool and resolve the IChannelFactory to create a few channels. This will definitely throw as soon as the IBusClient is being resolved.

Yet another option, if you have activated the management plugin in RabbitMQ would be to use it's RESTful API (which only responds if the broker is reachable).

Hope this helps!