rebus-org / Rebus.RabbitMq

:bus: RabbitMQ transport for Rebus
https://mookid.dk/category/rebus
Other
63 stars 44 forks source link

Cannot create the RabbitMQ ConnectionFactory with RequestedHeartbeat other than default (60 sec) #24

Closed dmitrynovik closed 6 years ago

dmitrynovik commented 6 years ago

I need to configure RabbitMQ connection heartbeat as described here: https://www.rabbitmq.com/heartbeats.html

// set the heartbeat timeout to 60 seconds
cf.RequestedHeartbeat = 60;

However, because Rebus effectively hides RabbitMQ connection factory inside its internal ConnectionManager, I cannot find the way to do it.

From what I see, the ConnectionManager creates the ConnectonFactory with some sort of default values which there is no way to override (ConnectionManager.cs):

connectionFactory = new ConnectionFactory
            {
                Uri = new Uri(uriStrings.First()), //Use the first URI in the list for ConnectionFactory to pick the AMQP credentials (if any)
                AutomaticRecoveryEnabled = true,
                NetworkRecoveryInterval = TimeSpan.FromSeconds(30),
                ClientProperties = CreateClientProperties(inputQueueAddress)
            };

It would be nice to expose the option to configure the ConnectionFactory's properties!

mookid8000 commented 6 years ago

I guess that's reasonable 😄

Do you think it would work if a "customization callback" could be provided, e.g. like this:

Configure.With(...)
    .Transport(t => {
        t.UseRabbitMq(...)
            .CustomizeConnectionFactory(factory => {
                // do what you want with the connection factory in here

                return factory;
            });
    })
    .(...)
    .Start();

?

mookid8000 commented 6 years ago

Oh well, I just did it – it's on NuGet.org as Rebus.RabbitMq 5.0.0-b01 now 😄 let me know if it works as it should

dmitrynovik commented 6 years ago

Thank you for a prompt response! The callback is an elegant solution (very little added code) and works like a charm.

mookid8000 commented 6 years ago

Good to hear 😄 if, after a while, you get tired of using a prerelease version, please report back here if it still works 😁 then I'll publish a package with a stable version number