public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration, string configSectionKey) { var retry = Policy .Handle <Exception>() .WaitAndRetryForever(retryAttempt => TimeSpan.FromMilliseconds(30)); var options = new RabbitMqOptions(); configuration.GetSection(configSectionKey).Bind(options); services.AddSingleton(context => options); retry.Execute(() => { var client = RawRabbitFactory.CreateSingleton(new RawRabbitOptions { ClientConfiguration = options }); services.AddSingleton <IBusClient>(_ => client); services.AddTransient <IBusPublisher, BusPublisher>(); }); }
public BusPublisher(IBusClient client, RabbitMqOptions options) { _busClient = client; _rabbitMqOptions = options; }