Ejemplo n.º 1
0
        public void Start()
        {
            var cashinSettings = new RabbitMqSubscriptionSettings
            {
                ConnectionString = _rabbitMqSettings.NewMeRabbitConnString,
                QueueName        = $"{_rabbitMqSettings.EventsExchange}.cashin.txhandler",
                ExchangeName     = _rabbitMqSettings.EventsExchange,
                RoutingKey       = ((int)MessageType.CashIn).ToString(),
                IsDurable        = QueueDurable
            };

            cashinSettings.DeadLetterExchangeName = $"{cashinSettings.QueueName}.dlx";

            var cashoutSettings = new RabbitMqSubscriptionSettings
            {
                ConnectionString = _rabbitMqSettings.NewMeRabbitConnString,
                QueueName        = $"{_rabbitMqSettings.EventsExchange}.cashout.txhandler",
                ExchangeName     = _rabbitMqSettings.EventsExchange,
                RoutingKey       = ((int)MessageType.CashOut).ToString(),
                IsDurable        = QueueDurable
            };

            cashoutSettings.DeadLetterExchangeName = $"{cashoutSettings.QueueName}.dlx";

            try
            {
                _cashinSubscriber = new RabbitMqSubscriber <CashInEvent>(_logFactory,
                                                                         cashinSettings,
                                                                         new ResilientErrorHandlingStrategy(_logFactory, cashinSettings,
                                                                                                            retryTimeout: TimeSpan.FromSeconds(20),
                                                                                                            retryNum: 3,
                                                                                                            next: new DeadQueueErrorHandlingStrategy(_logFactory, cashinSettings)))
                                    .SetMessageDeserializer(new ProtobufMessageDeserializer <CashInEvent>())
                                    .SetMessageReadStrategy(new MessageReadQueueStrategy())
                                    .SetAlternativeExchange(_rabbitMqSettings.AlternateConnectionString)
                                    .SetDeduplicator(MongoStorageDeduplicator.Create(_deduplicatorSettings.ConnectionString, _deduplicatorSettings.CollectionName))
                                    .Subscribe(ProcessCashinMessage)
                                    .CreateDefaultBinding()
                                    .Start();

                _cashoutSubscriber = new RabbitMqSubscriber <CashOutEvent>(_logFactory,
                                                                           cashoutSettings,
                                                                           new ResilientErrorHandlingStrategy(_logFactory, cashoutSettings,
                                                                                                              retryTimeout: TimeSpan.FromSeconds(20),
                                                                                                              retryNum: 3,
                                                                                                              next: new DeadQueueErrorHandlingStrategy(_logFactory, cashoutSettings)))
                                     .SetMessageDeserializer(new ProtobufMessageDeserializer <CashOutEvent>())
                                     .SetMessageReadStrategy(new MessageReadQueueStrategy())
                                     .SetAlternativeExchange(_rabbitMqSettings.AlternateConnectionString)
                                     .SetDeduplicator(MongoStorageDeduplicator.Create(_deduplicatorSettings.ConnectionString, _deduplicatorSettings.CollectionName))
                                     .Subscribe(ProcessCashoutMessage)
                                     .CreateDefaultBinding()
                                     .Start();
            }
            catch (Exception ex)
            {
                _log.Error(ex);
                throw;
            }
        }
        public void Start()
        {
            {
                var settings = new RabbitMqSubscriptionSettings
                {
                    ConnectionString       = _rabbitMqSettings.ConnectionString,
                    QueueName              = QueueName,
                    ExchangeName           = _rabbitMqSettings.ExchangeEthereumEvents,
                    DeadLetterExchangeName = $"{_rabbitMqSettings.ExchangeEthereumEvents}.dlx",
                    RoutingKey             = "",
                    IsDurable              = true
                };

                try
                {
                    var resilentErrorHandlingStrategyEth = new ResilientErrorHandlingStrategy(_logFactory, settings,
                                                                                              retryTimeout: TimeSpan.FromSeconds(10),
                                                                                              retryNum: 10,
                                                                                              next: new DeadQueueErrorHandlingStrategy(_logFactory, settings));

                    _subscriber = new RabbitMqSubscriber <CoinEvent>(_logFactory, settings, resilentErrorHandlingStrategyEth)
                                  .SetMessageDeserializer(new JsonMessageDeserializer <CoinEvent>())
                                  .SetMessageReadStrategy(new MessageReadQueueStrategy())
                                  .SetAlternativeExchange(settings.ConnectionString)
                                  .SetDeduplicator(MongoStorageDeduplicator.Create(_deduplicatorSettings.ConnectionString, _deduplicatorSettings.CollectionName))
                                  .Subscribe(SendEventToCqrs)
                                  .CreateDefaultBinding()
                                  .Start();
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    throw;
                }
            }

            #region HotWallet

            {
                string exchangeName = $"{_rabbitMqSettings.ExchangeEthereumEvents}.hotwallet";
                var    settings     = new RabbitMqSubscriptionSettings
                {
                    ConnectionString       = _rabbitMqSettings.ConnectionString,
                    QueueName              = HotWalletQueueName,
                    ExchangeName           = exchangeName,
                    DeadLetterExchangeName = $"{exchangeName}.dlx",
                    RoutingKey             = "",
                    IsDurable              = true
                };

                var resilentErrorHandlingStrategyEth = new ResilientErrorHandlingStrategy(_logFactory, settings,
                                                                                          retryTimeout: TimeSpan.FromSeconds(10),
                                                                                          retryNum: 10,
                                                                                          next: new DeadQueueErrorHandlingStrategy(_logFactory, settings));

                try
                {
                    _subscriberHotWallet = new RabbitMqSubscriber <HotWalletEvent>(_logFactory, settings,
                                                                                   resilentErrorHandlingStrategyEth)
                                           .SetMessageDeserializer(new JsonMessageDeserializer <HotWalletEvent>())
                                           .SetMessageReadStrategy(new MessageReadQueueStrategy())
                                           .SetAlternativeExchange(settings.ConnectionString)
                                           .SetDeduplicator(MongoStorageDeduplicator.Create(_deduplicatorSettings.ConnectionString, _deduplicatorSettings.CollectionName))
                                           .Subscribe(SendHotWalletEventToCqrs)
                                           .CreateDefaultBinding()
                                           .Start();
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    throw;
                }
            }

            #endregion
        }