Beispiel #1
0
        public void Configure()
        {
            _rabbitMqEndpoint.Initialize();

            var commandsExchangeName = RabbitMqExchangeNamesFactory.GetIntegrationCommandsExchangeName(_integrationName);
            var eventsExchangeName   = RabbitMqExchangeNamesFactory.GetIntegrationEventsExchangeName(_integrationName);

            _rabbitMqEndpoint.DeclareExchange(commandsExchangeName);
            _rabbitMqEndpoint.DeclareExchange(eventsExchangeName);

            var subscriptions = new MessageSubscriptionsRegistry()
                                .Handle <ReadBlockCommand>(o =>
            {
                o.WithHandler <ReadBlockCommandsHandler>();
            })
                                .AddFilter(new AppInsightTelemetryMessageFilter());

            _rabbitMqEndpoint.Subscribe(
                subscriptions,
                commandsExchangeName,
                $"bil-v2.bcn-{_integrationName}",
                messageConsumersCount: _rabbitMqSettings.MessageConsumersCount,
                messageProcessorsCount: _rabbitMqSettings.MessageProcessorsCount,
                defaultFirstLevelRetryTimeout: _rabbitMqSettings.DefaultFirstLevelRetryTimeout,
                maxFirstLevelRetryMessageAge: _rabbitMqSettings.MaxFirstLevelRetryMessageAge,
                maxFirstLevelRetryCount: _rabbitMqSettings.MaxFirstLevelRetryCount,
                firstLevelRetryQueueCapacity: _rabbitMqSettings.FirstLevelRetryQueueCapacity,
                processingQueueCapacity: _rabbitMqSettings.ProcessingQueueCapacity,
                replyExchangeName: eventsExchangeName);

            _rabbitMqEndpoint.StartListening();
        }
Beispiel #2
0
        public void Test_that_message_handler_with_state_dependencies_disposed_after_message_processing()
        {
            // Arrange

            using (var disposalEvent = new ManualResetEventSlim())
            {
                // ReSharper disable once AccessToDisposedClosure
                _testHandlerWithStateImplMock
                .Setup(x => x.Dispose())
                .Callback(() => { disposalEvent.Set(); });

                using (var endpoint = InitializeRabbitMqEndpoint(_serviceProvider))
                {
                    const string userState = "123";

                    var subscriptionsRegistry = new MessageSubscriptionsRegistry()
                                                .Handle <TestMessage, string>(o =>
                    {
                        o.WithHandler <TestMessageHandlerWithState>();
                        o.WithState(userState);
                    });

                    endpoint.Subscribe(subscriptionsRegistry, ExchangeName, RouteName);
                    endpoint.StartListening();

                    var publisher = endpoint.CreatePublisher(ExchangeName);

                    var messageId = Guid.NewGuid();

                    // Act

                    publisher.Publish(new TestMessage
                    {
                        Id = messageId
                    });

                    disposalEvent.Wait(Waiting.Timeout);

                    // Assert

                    Assert.True(disposalEvent.IsSet, "Disposable dependency should be disposed after message processing");

                    _testHandlerWithStateImplMock.Verify
                    (
                        x => x.HandleAsync
                        (
                            It.Is <string>(s => s == userState),
                            It.Is <TestMessage>(m => m.Id == messageId),
                            It.IsNotNull <MessageHeaders>(),
                            It.IsNotNull <IMessagePublisher>()
                        ),
                        times: Times.Once
                    );
                }
            }
        }
Beispiel #3
0
        public void Initialize()
        {
            _endpoint.Initialize();

            foreach (var integrationName in _integrationNames)
            {
                _log.Info($"Initializing RabbitMq endpoint for the blockchain integration {integrationName}...");

                var kebabIntegrationName = integrationName.CamelToKebab();
                var commandsExchangeName = RabbitMqExchangeNamesFactory.GetIntegrationCommandsExchangeName(kebabIntegrationName);
                var eventsExchangeName   = RabbitMqExchangeNamesFactory.GetIntegrationEventsExchangeName(kebabIntegrationName);

                _endpoint.DeclareExchange(commandsExchangeName);
                _endpoint.DeclareExchange(eventsExchangeName);

                var subscriptions = new MessageSubscriptionsRegistry()
                                    .Handle <BlockHeaderReadEvent, string>(o =>
                {
                    o.WithHandler <IBlockEventsHandler>();
                    o.WithState(integrationName);
                })
                                    .Handle <BlockNotFoundEvent, string>(o =>
                {
                    o.WithHandler <IBlockEventsHandler>();
                    o.WithState(integrationName);
                })
                                    .Handle <TransferAmountTransactionsBatchEvent, string>(o =>
                {
                    o.WithHandler <IBlockEventsHandler>();
                    o.WithState(integrationName);
                })
                                    .Handle <TransferCoinsTransactionsBatchEvent, string>(o =>
                {
                    o.WithHandler <IBlockEventsHandler>();
                    o.WithState(integrationName);
                })
                                    .Handle <LastIrreversibleBlockUpdatedEvent, string>(o =>
                {
                    o.WithHandler <IBlockEventsHandler>();
                    o.WithState(integrationName);
                });

                foreach (var filter in _messageFilters)
                {
                    subscriptions.AddFilter(filter);
                }

                _endpoint.Subscribe
                (
                    subscriptions,
                    eventsExchangeName,
                    $"bil-v2.{_clientName}",
                    _defaultFirstLevelRetryTimeout,
                    _maxFirstLevelRetryMessageAge,
                    _maxFirstLevelRetryCount,
                    _firstLevelRetryQueueCapacity,
                    _processingQueueCapacity,
                    _messageConsumersCount,
                    _messageProcessorsCount
                );
            }
        }