示例#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();
        }
        private static void RegisterIrreversibleBlocksRetrievingStrategy <TAppSettings>(
            IServiceCollection services,
            BlocksReaderServiceOptions <TAppSettings> options,
            IReloadingManager <TAppSettings> settings)

            where TAppSettings : IBlocksReaderSettings <BaseBlocksReaderDbSettings, BaseBlocksReaderRabbitMqSettings>
        {
            var kebabIntegrationName = options.IntegrationName.CamelToKebab();
            var eventsExchangeName   = RabbitMqExchangeNamesFactory.GetIntegrationEventsExchangeName(kebabIntegrationName);

            switch (options.IrreversibleBlockRetrievingStrategy)
            {
            case IrreversibleBlockRetrievingStrategy.NotSupported:
                break;

            case IrreversibleBlockRetrievingStrategy.Pulling:
                services.AddSingleton <IIrreversibleBlockMonitor>(s =>
                                                                  new IrreversibleBlockMonitor(
                                                                      s.GetRequiredService <ILogFactory>(),
                                                                      s.GetRequiredService <IIrreversibleBlockProvider>(),
                                                                      s.GetRequiredService <IIrreversibleBlockListener>(),
                                                                      settings.CurrentValue.LastIrreversibleBlockMonitoringPeriod));
                services.AddTransient <IIrreversibleBlockListener>(s =>
                                                                   new IrreversibleBlockListener(
                                                                       () => s.GetRequiredService <IRabbitMqEndpoint>().CreatePublisher(eventsExchangeName)));
                services.AddTransient(s =>
                                      options.IrreversibleBlockProviderFactory(new ServiceFactoryContext <TAppSettings>(s, settings)));
                break;

            case IrreversibleBlockRetrievingStrategy.Pushing:
                services.AddTransient <IIrreversibleBlockListener>(s =>
                                                                   new IrreversibleBlockListener(
                                                                       () => s.GetRequiredService <IRabbitMqEndpoint>().CreatePublisher(eventsExchangeName)));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(options.IrreversibleBlockRetrievingStrategy), options.IrreversibleBlockRetrievingStrategy, "Unknown strategy");
            }
        }
示例#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
                );
            }
        }