使用 RabbitMQ 的 MassTransit 中的连接事件 [英] Connection events in MassTransit with RabbitMQ
问题描述
我想问一下 MassTransit 是否可以在 RabbitMQ 连接状态更改时通知客户端应用程序.我查了 IBusObserver,但是当 MassTransit 与 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.
推荐答案
您需要改用 IReceiveEndpointObserver
实例.
以下是一个如何完成的示例,MassTransit 为支持 ASP.NET Core 运行状况检查所做的工作:https://github.com/MassTransit/MassTransit/blob/develop/src/Containers/MassTransit.AspNetCoreIntegration/HealthChecks/ReceiveEndpointHealthCheck.cs
Here is an example of how it can be done, what MassTransit does to support ASP.NET Core health checks: https://github.com/MassTransit/MassTransit/blob/develop/src/Containers/MassTransit.AspNetCoreIntegration/HealthChecks/ReceiveEndpointHealthCheck.cs
您在配置端点时附加观察者:
You attach the observer when configuring the endpoint:
Bus.Factory.CreateUsingRabbitMq(cfg =>
{
// host and other things
...
cfg.ReceiveEndpoint("my_endpoint", ep =>
{
// consumers
...
ep.ConnectReceiveEndpointObserver(observer);
}
}
这篇关于使用 RabbitMQ 的 MassTransit 中的连接事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!