Exemplo n.º 1
0
            public void should_set_qos()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler"">
                                <qos prefetchCount=""8"" />
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();
                var busConfigurator = new BusConfiguration();

                busConfigurator.UseRabbitMq();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);
                var result  = sut.Configure("producer", busConfigurator);

                RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)result).ReceiverDefaults as RabbitReceiverOptions;

                Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя.");
                Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS();

                Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен.");
                Assert.AreEqual(8, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков.");
            }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RabbitReceiver"/> class.
 /// </summary>
 /// <param name="bus">A reference to the bus containing the receiver</param>
 /// <param name="configuration">
 /// The configuration.
 /// </param>
 /// <param name="connectionPool">
 /// A bus connection pool
 /// </param>
 public RabbitReceiver(RabbitBus bus, IReceiverConfiguration configuration, IConnectionPool <IRabbitConnection> connectionPool)
     : base(configuration)
 {
     this.bus             = bus;
     this.connectionPool  = connectionPool;
     this.receiverOptions = (RabbitReceiverOptions)configuration.Options;
     this.logger          = LogManager.GetLogger($"{this.GetType().FullName}(Endpoint=\"{this.bus.Endpoint}\")");
 }
Exemplo n.º 3
0
        /// <summary>
        /// The ensure configuration is compatible.
        /// </summary>
        /// <param name="listener">
        /// The listener.
        /// </param>
        /// <param name="configuration">
        /// The configuration.
        /// </param>
        /// <exception cref="BusConfigurationException">
        /// </exception>
        private static void EnsureConfigurationIsCompatible(Listener listener, IReceiverConfiguration configuration)
        {
            RabbitReceiverOptions existing = listener.ReceiverOptions;
            var other = (RabbitReceiverOptions)configuration.Options;

            Action <Func <RabbitReceiverOptions, object>, string> compareAndThrow = (getOption, optionName) =>
            {
                if (getOption(existing) != getOption(other))
                {
                    throw new BusConfigurationException("Listener on [{0}] is not compatible with subscription of [{1}] due to option mismatch [{2}].".FormatEx(listener.Endpoint.ListeningSource, configuration.Label, optionName));
                }
            };

            compareAndThrow(o => o.IsAcceptRequired(), "AcceptIsRequired");
            compareAndThrow(o => o.GetParallelismLevel(), "ParallelismLevel");
            compareAndThrow(o => o.GetFailedDeliveryStrategy(), "FailedDeliveryStrategy");
            compareAndThrow(o => o.GetQoS(), "QoS");
        }
Exemplo n.º 4
0
            public void should_be_default()
            {
                const string ProducerConfig =
                    @"<endpoints>
                            <endpoint name=""producer"" connectionString=""amqp://localhost/integration"" lifecycleHandler=""ProducerHandler"">
                            </endpoint>
                        </endpoints>";

                Mock <IDependencyResolver> dependencyResoverMock = new Mock <IDependencyResolver>();

                var section = new XmlEndpointsSection(ProducerConfig);
                var sut     = new AppConfigConfigurator(section, dependencyResoverMock.Object);

                using (var bus = new BusFactory().Create(cfg => sut.Configure("producer", cfg), false))
                {
                    RabbitReceiverOptions rabbitReceiverOptions = ((BusConfiguration)bus.Configuration).ReceiverDefaults as RabbitReceiverOptions;
                    Assert.IsNotNull(rabbitReceiverOptions, "Долны быть установлены настройки получателя.");
                    Maybe <QoSParams> qosMaybe = rabbitReceiverOptions.GetQoS();
                    Assert.IsTrue(qosMaybe.HasValue, "QoS должен быть установлен.");
                    Assert.AreEqual(50, qosMaybe.Value.PrefetchCount, "Должно быть установлено количество потоков.");
                }
            }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Listener"/> class.
        /// </summary>
        /// <param name="busContext">
        /// The bus Context.
        /// </param>
        /// <param name="connection">
        /// Соединение с шиной сообщений
        /// </param>
        /// <param name="endpoint">
        /// Прослушиваемый порт.
        /// </param>
        /// <param name="receiverOptions">
        /// Настройки получателя.
        /// </param>
        /// <param name="validatorRegistry">
        /// Реестр механизмов проверки сообщений.
        /// </param>
        public Listener(IBusContext busContext, IRabbitConnection connection, ISubscriptionEndpoint endpoint, RabbitReceiverOptions receiverOptions, MessageValidatorRegistry validatorRegistry)
        {
            this.busContext = busContext;
            this.connection = connection;

            this.endpoint          = endpoint;
            this.validatorRegistry = validatorRegistry;

            this.ReceiverOptions = receiverOptions;
            this.BrokerUrl       = connection.ConnectionString;

            this.messageHeaderStorage = this.ReceiverOptions.GetIncomingMessageHeaderStorage().Value;

            this.logger = LogManager.GetLogger($"{this.GetType().FullName}({this.BrokerUrl}, {this.GetHashCode()})");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="Listener"/>.
        /// </summary>
        /// <param name="channelProvider">
        /// Поставщик каналов.
        /// </param>
        /// <param name="endpoint">
        /// Прослушиваемый порт.
        /// </param>
        /// <param name="receiverOptions">
        /// Настройки получателя.
        /// </param>
        /// <param name="validatorRegistry">
        /// Реестр механизмов проверки сообщений.
        /// </param>
        public Listener(IChannelProvider channelProvider, ISubscriptionEndpoint endpoint, RabbitReceiverOptions receiverOptions, MessageValidatorRegistry validatorRegistry)
        {
            this.endpoint          = endpoint;
            this.channelProvider   = channelProvider;
            this.validatorRegistry = validatorRegistry;

            this.ReceiverOptions = receiverOptions;
            this.ReceiverOptions.GetIncomingMessageHeaderStorage();
            this.messageHeaderStorage = this.ReceiverOptions.GetIncomingMessageHeaderStorage().Value;

            // TODO: refactor
            this.Failed += _ =>
            {
                if (HasFailed)
                {
                    return;
                }

                this.HasFailed = true;
                ((IBusAdvanced)channelProvider).Panic();
            };     // restarting the whole bus
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Listener"/> class.
        /// </summary>
        /// <param name="busContext">
        /// The bus Context.
        /// </param>
        /// <param name="connection">
        /// Соединение с шиной сообщений
        /// </param>
        /// <param name="endpoint">
        /// Прослушиваемый порт.
        /// </param>
        /// <param name="receiverOptions">
        /// Настройки получателя.
        /// </param>
        /// <param name="validatorRegistry">
        /// Реестр механизмов проверки сообщений.
        /// </param>
        public Listener(IBusContext busContext, IRabbitConnection connection, ISubscriptionEndpoint endpoint, RabbitReceiverOptions receiverOptions, MessageValidatorRegistry validatorRegistry)
        {
            this.busContext        = busContext;
            this.connection        = connection;
            this.endpoint          = endpoint;
            this.validatorRegistry = validatorRegistry;

            this.ReceiverOptions = receiverOptions;
            this.BrokerUrl       = connection.ConnectionString;
            this.logger          = LogManager.GetLogger($"{this.GetType().FullName}(URL={this.BrokerUrl})");

            this.ReceiverOptions.GetIncomingMessageHeaderStorage();
            this.messageHeaderStorage = this.ReceiverOptions.GetIncomingMessageHeaderStorage().Value;

            this.Failed += _ =>
            {
                if (this.HasFailed)
                {
                    return;
                }

                this.HasFailed = true;
            };
        }