public void should_use_registered_validator()
            {
                var registry = new MessageValidatorRegistry();

                registry.Register(new BooValidator());

                var payload = new Boo {
                    Num = 3, Str = "this"
                };

                registry.Invoking(r => r.Validate(new Message <Boo>("label".ToMessageLabel(), payload))).
                ShouldThrow <MessageValidationException>();
            }
Exemplo n.º 2
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.º 3
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
        }
            public void should_replace_validator()
            {
                var registry = new MessageValidatorRegistry();

                registry.Register(new BooValidator());

                var stubValidator = new Mock <IMessageValidatorOf <Boo> >();

                stubValidator.Setup(v => v.Validate(It.IsAny <IMessage>())).
                Returns(ValidationResult.Valid);

                registry.Register(stubValidator.Object);

                var payload = new Boo {
                    Num = 3, Str = "this"
                };

                registry.Invoking(r => r.Validate(new Message <Boo>("label".ToMessageLabel(), payload))).
                ShouldNotThrow();

                stubValidator.Verify(v => v.Validate(It.IsAny <IMessage>()), Times.Once);
            }
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.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;
            };
        }