简体   繁体   English

Masstransit是否需要设置心跳

[英]Is It Required to Set Heartbeat in Masstransit

I am implementing a .NET Core Worker Service (hosted as a windows service) with Masstransit consumers using RabbitMQ transport.我正在使用 RabbitMQ 传输与 Masstransit 消费者实施 .NET Core Worker Service(托管为 windows 服务)。 As per the nature of the application, consumers might not get messages frequently.根据应用程序的性质,消费者可能不会经常收到消息。

Will the connection between the server be closed if there is a considerable idle time period?如果有相当长的空闲时间,服务器之间的连接会被关闭吗?

As I saw, now RabbitMQ automatically handles reconnection based on heartbeats and there is a default heartbeat interval of 60 seconds.如我所见,现在 RabbitMQ 会根据心跳自动处理重新连接,并且默认心跳间隔为 60 秒。 So that do I need to set the heartbeat value when configuring the RabbitMQ host while configuring the Masstransit as well?那么在配置Masstransit的同时配置RabbitMQ主机时是否需要设置心跳值?

Following is part of the code on how I configured Masstransit.以下是我如何配置 Masstransit 的部分代码。

services.AddMassTransit(configurator =>
                {

                    configurator.AddConsumer<LocationCreatedConsumer>();

                    switch (configuration.GetValue<string>("EventBus:EventBusTransport"))
                    {
                        case "rabbitmq":
                            configurator.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(config =>
                            {
                                config.Host(configuration.GetValue<string>("EventBus:EventBusUri"), "/", hostConfigurator =>
                                {
                                    hostConfigurator.Username(configuration.GetValue<string>("EventBus:EventBusUserName"));
                                    hostConfigurator.Password(configuration.GetValue<string>("EventBus:EventBusPassword"));
                                    hostConfigurator.Heartbeat(TimeSpan.FromSeconds(300)); // Is this required???
                                });
                            }));
                            break;
                    }
                });

I have looked into Masstransit documentation as well, but couldn't get it clarified.我也查看了 Masstransit 文档,但无法澄清。 Any help would be appreciated.任何帮助,将不胜感激。 Thanks.谢谢。

MassTransit defaults to TimeSpan.Zero , so unless specified there is no heartbeat configured. MassTransit 默认为TimeSpan.Zero ,因此除非指定,否则不会配置心跳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM