예제 #1
0
        public static IServiceCollection AddEventBus(this IServiceCollection service, IConfiguration configuration)
        {
            var settings = new RabbitMqConnectionSettings();

            configuration.GetSection(ConfigSectionName).Bind(settings);
            service.AddSingleton <IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
            service.AddSingleton <IEventBus, RabbitMQEventBus>(sp =>
                                                               new RabbitMQEventBus(sp, settings.SubscriberId, settings.Retry, settings.BrokerName));
            return(service);
        }
예제 #2
0
        public static IServiceCollection AddBrokerServiceConnection(this IServiceCollection service, IConfiguration configuration)
        {
            var settings = new RabbitMqConnectionSettings();

            configuration.GetSection(ConfigSectionName).Bind(settings);
            service.AddSingleton <IAmqpConnection>(sp =>
            {
                var logger            = sp.GetRequiredService <ILogger <RabbitMQConnection> >();
                var connectionFactory = new ConnectionFactory
                {
                    HostName = settings.HostName,
                    Port     = settings.Port,
                    UserName = settings.UserName,
                    Password = settings.Password,
                };

                return(new RabbitMQConnection(connectionFactory, logger, settings.Retry));
            });
            return(service);
        }