Is It Required to Set Heartbeat in Masstransit

Viewed 392

I am implementing a .NET Core Worker Service (hosted as a windows service) with Masstransit consumers using RabbitMQ transport. 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. So that do I need to set the heartbeat value when configuring the RabbitMQ host while configuring the Masstransit as well?

Following is part of the code on how I configured 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. Any help would be appreciated. Thanks.

1 Answers

MassTransit defaults to TimeSpan.Zero, so unless specified there is no heartbeat configured.

Related