コード例 #1
0
        public void AddServices(IServiceCollection services)
        {
            var config = new EventBusRabbitMQOptions();

            _configure?.Invoke(config);

            var connectionFactory = new ConnectionFactory {
                HostName    = config.HostName,
                Port        = config.Port,
                UserName    = config.UserName,
                Password    = config.Password,
                VirtualHost = config.VirtualHost,
                AutomaticRecoveryEnabled = true
            };

            services.AddSingleton <IRabbitMQPersistentConnection>(sp => new DefaultRabbitMQPersistentConnection(connectionFactory, sp.GetRequiredService <ILogger <DefaultRabbitMQPersistentConnection> >()));
            services.AddSingleton <IEventBus>(sp => new EventBusRabbitMQ(sp.GetRequiredService <IRabbitMQPersistentConnection>(), sp.GetRequiredService <ILogger <EventBusRabbitMQ> >(), sp.GetRequiredService <IEventBusSubscriptionsManager>(), config.QueueName));
        }
コード例 #2
0
        public void AddServices(IServiceCollection services)
        {
            var config = new EventBusRabbitMQOptions();

            _configure?.Invoke(config);

            var connectionFactory = new ConnectionFactory {
                HostName    = config.HostName,
                Port        = config.Port,
                UserName    = config.UserName,
                Password    = config.Password,
                VirtualHost = config.VirtualHost,
                AutomaticRecoveryEnabled = true
            };

            services.AddSingleton <IEventBus>(sp => new RabbitMQEventBus(connectionFactory,
                                                                         sp.GetRequiredService <ILogger <RabbitMQEventBus> >(),
                                                                         sp.GetRequiredService <IEventHandlerExecutionContext>(),
                                                                         config.ExchangeName,
                                                                         queueName: config.QueueName));
        }