public static IBusControl ConfigureBus(
IServiceProvider serviceProvider,
RabbitMQSettings configuration,
List<ConsumerConfig> consumers = null,
Action<IRabbitMqBusFactoryConfigurator> customConfiguration = null)
{
var defaultServer = configuration.Servers.First();
return Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.UseSerilogEnricher();
var loggerFactory = serviceProvider.GetRequiredService<ILoggerFactory>();
cfg.UseExtensionsLogging(loggerFactory);
var host = cfg.Host(new Uri($"rabbitmq://{defaultServer}:/"), h =>
{
h.Username(configuration.Username);
h.Password(configuration.Password);
h.PublisherConfirmation = false;
h.UseCluster(c => c.ClusterMembers = configuration.Servers);
});
if (!string.IsNullOrWhiteSpace(configuration.ServiceName) && consumers?.Any() == true && !configuration.DisableConsuming)
{
foreach (var consumer in consumers)
{
var queueName = new QueueNameBuilder().GetQueueName(configuration.ServiceName, consumer.ConsumerType);
cfg.ReceiveEndpoint(host, queueName, e => {
e.UseMessageRetry(r => r.Interval(configuration.RetryCount, TimeSpan.FromSeconds(configuration.RetryIntervalSec)));
// find and call e.Consumer<Consumer>();
e.Consumer(new ConsumerBuilder().BuildType(consumer.ConsumerType), t => serviceProvider.CreateScope().ServiceProvider.GetService(t));
});
}
}
customConfiguration?.Invoke(cfg);
});
}
I'm not sure if it's an issue with the library which doesn't work well with a cluster.