Search code examples
rabbitmqmasstransit

Connection events in MassTransit with RabbitMQ


I would like to ask is there for MassTransit to notify the client application on RabbitMQ connection state change. I checked IBusObserver, but there is not information when MassTransit disconnects with RabbitMQ.

This is an important function because, in case of disconnection and reconnection, I have to send a message with the current state of the application.


Solution

  • The original answer is about MT 6.

    You need to use the IReceiveEndpointObserver instance instead. Attach the observer when configuring the endpoint:

    Bus.Factory.CreateUsingRabbitMq(cfg =>
    {
        // host and other things
        ...
        cfg.ReceiveEndpoint("my_endpoint", ep =>
        {
            // consumers
            ...
            ep.ConnectReceiveEndpointObserver(observer);
        }
    }
    

    MT 8 allows registering endpoint observers

    From the docs:

    services.AddReceiveEndpointObserver<ReceiveEndpointObserver>();