示例#1
0
        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>();
            });
        }
示例#2
0
 public BusPublisher(IBusClient client, RabbitMqOptions options)
 {
     _busClient       = client;
     _rabbitMqOptions = options;
 }