Example #1
0
        public DefaultRabbitMqPersistentConnection(ILogger <DefaultRabbitMqPersistentConnection> logger, IOptions <BusSetting> options)
        {
            _logger            = logger;
            _options           = options.Value;
            _connectionFactory = new ConnectionFactory
            {
                HostName      = _options.Connection
                , UserName    = _options.UserName
                , Password    = _options.Password
                , VirtualHost = _options.VirtualHost
                , AutomaticRecoveryEnabled = _options.AutomaticRecoveryEnabled
                , ClientProperties         = new Dictionary <string, object>
                {
                    { "Product", _options.AppId }
                }
            };

            if (_options.RequestedHeartbeatSeconds != default)
            {
                _connectionFactory.RequestedHeartbeat = (ushort)_options.RequestedHeartbeatSeconds.TotalSeconds;
            }

            try
            {
                EnsureDeclarations();
            }
            catch (Exception e)
            {
                _logger.LogCritical(e, "RabbitMQ declarations are experiencing issue.");
                throw;
            }
        }
Example #2
0
        // ReSharper disable once SuggestBaseTypeForParameter
        public EventBusRabbitMq(IServiceProvider serviceProvider, ILogger <EventBusRabbitMq> logger, IOptions <BusSetting> options, IRabbitMqPersistentConnection persistentConnection, IEventBusSubscriptionsManager subscriptionsManager)
        {
            _serviceProvider = serviceProvider;
            _logger          = logger;
            _options         = options.Value;

            _persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
            _subscriptionsManager = subscriptionsManager ?? _serviceProvider.GetRequiredService <InMemoryEventBusSubscriptionsManager>();

            //_consumerChannel = CreateConsumerChannel();
            _subscriptionsManager.OnEventRemoved += SubsManager_OnEventRemoved;
        }