Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EasyNetQBroker"/> class.
        /// </summary>
        /// <param name="createBus">create bus method</param>
        /// <param name="connectionString">rabbitmq connection string</param>
        /// <param name="exchangeName">exchange name</param>
        /// <param name="tombQueue">queue name</param>
        /// <param name="environmentNamingConventionController">environment naming convention controller</param>
        public EasyNetQBroker(
            Func <string, EventHandler, EventHandler, Action <IServiceRegister>, IAdvancedBus> createBus,
            string connectionString, string exchangeName, string tombQueue,
            IEnvironmentNamingConventionController environmentNamingConventionController)
        {
            _disconnectedActions = new ConcurrentDictionary <Action, bool>();

            Bus = createBus(
                connectionString,
                (s, e) =>
            {
                _logger.Information("Rabbitmq bus connected");
            },
                (s, e) =>
            {
                _logger.Information("Rabbitmq bus disconnected");

                foreach (var record in _disconnectedActions.ToArray())
                {
                    try
                    {
                        record.Key?.Invoke();
                    }
                    catch (Exception exp)
                    {
                        _logger.Error(exp, $"Failed to execute disconnect callback {exp.Message}");
                    }
                    finally
                    {
                        // call action only one time
                        _disconnectedActions.Remove(record.Key);
                    }
                }
            },
                register => register.Register <IEventBus>(provider =>
            {
                var eventBus = new EventBus();
                eventBus.Subscribe <StartConsumingFailedEvent>(
                    x =>
                {
                    _logger.Error($"Failed to connect to queue {x.Queue.Name}");
                });
                return(eventBus);
            }));

            var conventions = Bus.Container.Resolve <IConventions>();

            if (conventions != null)
            {
                conventions.ErrorQueueNamingConvention    = () => environmentNamingConventionController.GetQueueName(tombQueue);
                conventions.ErrorExchangeNamingConvention = messageReceivedInfo => exchangeName + "_error";
            }
        }
Example #2
0
 public EasyNetQSubscriberFactory(IBroker broker, string exchangename,
                                  string waitexchangename,
                                  ISubscriberController subscriberController,
                                  IEnvironmentNamingConventionController environmentNamingConventionController,
                                  int retryfactor, IPublisher publisher)
 {
     _broker = broker;
     _bus    = broker.Bus;
     _subscriberController                  = subscriberController;
     _exchange                              = new AsyncLazy <IExchange>(async() => await _bus.ExchangeDeclareAsync(exchangename, ExchangeType.Topic));
     _easyNetQPublisherToWaitExchange       = new EasyNetQPublisher(_bus, waitexchangename, environmentNamingConventionController);
     _environmentNamingConventionController = environmentNamingConventionController;
     _retryfactor                           = retryfactor;
     _publisher                             = publisher;
 }
Example #3
0
 public EasyNetQQueueInfoProvider(IEnvironmentNamingConventionController environmentNamingConventionController, IBroker broker)
 {
     _environmentNamingConventionController = environmentNamingConventionController;
     _bus = broker.Bus;
 }