Ejemplo n.º 1
0
    public RabbitMqPublisherConnection(RabbitMqPublisherOptions options, IRabbitMqConnection connection, ILogger <RabbitMqPublisherConnection> logger)
    {
        Options = options;
        _logger = logger;

        _connection = new Lazy <IConnection>(() =>
        {
            _logger.LogWarning("Creating publisher RabbitMQ connection");

            var physicalConnection = connection.Create(ConnectionType.Publisher);

            physicalConnection.CallbackException   += OnPhysicalConnectionCallbackException;
            physicalConnection.ConnectionBlocked   += OnPhysicalConnectionBlocked;
            physicalConnection.ConnectionShutdown  += OnPhysicalConnectionShutdown;
            physicalConnection.ConnectionUnblocked += OnPhysicalConnectionUnblocked;

            return(physicalConnection);
        });
    }
        public StreamFlowRabbitMq(IServiceCollection services, StreamFlowOptions options)
        {
            _services = services;
            _options  = options;

            services.TryAddSingleton <IRabbitMqConventions, RabbitMqConventions>();
            services.TryAddSingleton <IMessageSerializer, RabbitMqMessageSerializer>();
            services.TryAddSingleton <IOutboxMessageAddressProvider, RabbitMqMessageAddressProvider>();
            services.TryAddScoped <ILoggerScopeStateFactory, LoggerScopeStateFactory>();
            services.TryAddSingleton <IRabbitMqMetrics, RabbitMqNoOpMetrics>();

            services.TryAddScoped <IPublisher, RabbitMqPublisher>();
            services.TryAddSingleton <IRabbitMqPublisherChannel, RabbitMqPublisherChannel>();
            services.TryAddSingleton <IRabbitMqPublisherBus, RabbitMqPublisherBus>();

            _publisherOptions = new RabbitMqPublisherOptions();
            services.AddSingleton(_publisherOptions);

            _consumerOptions = new RabbitMqConsumerOptions();
            services.AddSingleton(_consumerOptions);
        }