Пример #1
0
        static IConsumingService CreateService(
            IRabbitMqConnectionFactory connectionFactory,
            IMessageHandlingPipelineExecutingService messageHandlingPipelineExecutingService)
        {
            var guid = Guid.NewGuid();
            var connectionOptionContainer = new RabbitMqConnectionOptionsContainer
            {
                Guid    = guid,
                Options = new RabbitMqConnectionOptions
                {
                    ConsumerOptions = new RabbitMqClientOptions()
                }
            };
            var loggerMock = new Mock <ILogger <QueueService> >();

            return(new QueueService(
                       guid,
                       connectionFactory,
                       new List <RabbitMqConnectionOptionsContainer> {
                connectionOptionContainer
            },
                       messageHandlingPipelineExecutingService,
                       new List <RabbitMqExchange>(),
                       loggerMock.Object));
        }
Пример #2
0
        void ConfigureConnectionInfrastructure(RabbitMqConnectionOptionsContainer optionsContainer)
        {
            Connection = _rabbitMqConnectionFactory.CreateRabbitMqConnection(optionsContainer?.Options?.ProducerOptions);
            if (Connection != null)
            {
                Connection.CallbackException += HandleConnectionCallbackException;
                if (Connection is IAutorecoveringConnection connection)
                {
                    connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
                }
                Channel = Connection.CreateModel();
                Channel.CallbackException += HandleChannelCallbackException;
                Channel.BasicRecoverOk    += HandleChannelBasicRecoverOk;
            }

            ConsumingConnection = _rabbitMqConnectionFactory.CreateRabbitMqConnection(optionsContainer?.Options?.ConsumerOptions);
            if (ConsumingConnection != null)
            {
                ConsumingConnection.CallbackException += HandleConnectionCallbackException;
                if (Connection is IAutorecoveringConnection connection)
                {
                    connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
                }
                ConsumingChannel = ConsumingConnection.CreateModel();
                ConsumingChannel.CallbackException += HandleChannelCallbackException;
                ConsumingChannel.BasicRecoverOk    += HandleChannelBasicRecoverOk;

                _consumer = _rabbitMqConnectionFactory.CreateConsumer(ConsumingChannel);
            }
        }
Пример #3
0
 public DefaultRabbitMQPersistentConnection(ConnectionFactory connectionFactory, IConfiguration configuration,
                                            ILogger <DefaultRabbitMQPersistentConnection> logger, RabbitMqConnectionOptionsContainer optionsContainer,
                                            IHostApplicationLifetime hostApplicationLifetime)
 {
     _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
     _logger            = logger;
     _optionsContainer  = optionsContainer;
     _lifetime          = hostApplicationLifetime;
     _retryCount        = string.IsNullOrEmpty(configuration["EventBusRetryCount"])
                         ? 5
                         : int.Parse(configuration["EventBusRetryCount"]);
 }
Пример #4
0
        internal static IServiceCollection ConfigureRabbitMqConsumingClientOptions(this IServiceCollection services, Guid guid, RabbitMqClientOptions options)
        {
            var container = new RabbitMqConnectionOptionsContainer
            {
                Guid    = guid,
                Options = new RabbitMqConnectionOptions {
                    ConsumerOptions = options
                }
            };

            return(services.AddRabbitMqConnectionOptionsContainer(container));
        }
Пример #5
0
        void ConfigureConnectionInfrastructure(RabbitMqConnectionOptionsContainer optionsContainer)
        {
            Connection = RabbitMqFactoryExtensions.CreateRabbitMqConnection(optionsContainer?.Options?.ProducerOptions);
            if (Connection != null)
            {
                Connection.CallbackException       += HandleConnectionCallbackException;
                Connection.ConnectionRecoveryError += HandleConnectionRecoveryError;
                Channel = Connection.CreateModel();
                Channel.CallbackException += HandleChannelCallbackException;
                Channel.BasicRecoverOk    += HandleChannelBasicRecoverOk;
            }

            ConsumingConnection = RabbitMqFactoryExtensions.CreateRabbitMqConnection(optionsContainer?.Options?.ConsumerOptions);
            if (ConsumingConnection != null)
            {
                ConsumingConnection.CallbackException       += HandleConnectionCallbackException;
                ConsumingConnection.ConnectionRecoveryError += HandleConnectionRecoveryError;
                ConsumingChannel = ConsumingConnection.CreateModel();
                ConsumingChannel.CallbackException += HandleChannelCallbackException;
                ConsumingChannel.BasicRecoverOk    += HandleChannelBasicRecoverOk;

                _consumer = new AsyncEventingBasicConsumer(ConsumingChannel);
            }
        }
Пример #6
0
        static IServiceCollection AddRabbitMqConnectionOptionsContainer(this IServiceCollection services, RabbitMqConnectionOptionsContainer container)
        {
            var serviceDescriptor = new ServiceDescriptor(typeof(RabbitMqConnectionOptionsContainer), container);

            services.Add(serviceDescriptor);
            return(services);
        }