Beispiel #1
0
        public ConsumeService(RabitMqOption config, string dbtable, IDbTransfer dbTypeMapper) : base(config)
        {
            _dbTypeMapper = dbTypeMapper;
            var queueName = !string.IsNullOrEmpty(config.CanalDestinationName) ? $"{config.CanalDestinationName}." : "";

            queueName += dbtable;
            base.Queues.Add(new QueueInfo()
            {
                ExchangeType = ExchangeType.Direct,
                Queue        = queueName,
                RouterKey    = queueName,
                OnReceived   = this.OnReceived,
            });
        }
Beispiel #2
0
        public ConsumerService(ILogger <ConsumerService> logger, IOptions <RedisOption> redisOptions, IConfiguration configuration, IDbTransfer dbTypeMapper)
        {
            _logger        = logger;
            _configuration = configuration;
            _dbTypeMapper  = dbTypeMapper;
            var redisOptions1 = redisOptions?.Value;

            if (redisOptions1 == null)
            {
                redisOptions1 = new RedisOption();
            }

            UpdateFromEnv(redisOptions1);

            if (string.IsNullOrEmpty(redisOptions1.ConnectString))
            {
                throw new ArgumentNullException(nameof(RedisOption.ConnectString));
            }

            if (!redisOptions1.DbTables.Any())
            {
                throw new ArgumentNullException(nameof(RedisOption.DbTables));
            }


            ConfigurationOptions connectOptions = ConfigurationOptions.Parse(redisOptions1.ConnectString);

            if (redisOptions1.ReconnectTimeout < 5000)
            {
                redisOptions1.ReconnectTimeout = 5000;
            }
            connectOptions.ReconnectRetryPolicy = new LinearRetry(redisOptions1.ReconnectTimeout);

            _conn = ConnectionMultiplexer.Connect(connectOptions);
            Redis = _conn.GetDatabase();

            foreach (var dbtable in redisOptions1.DbTables)
            {
                var queueName = !string.IsNullOrEmpty(redisOptions1.CanalDestinationName) ? $"{redisOptions1.CanalDestinationName}." : "";
                queueName += dbtable;
                _topicList.Add(queueName);
            }

            _logger.LogInformation($"Redis [{redisOptions1.ConnectString}] connect success");
        }
Beispiel #3
0
        public MysqlHandler(ILogger <MysqlHandler> logger, IOptions <MysqlOption> options, IDbTransfer dbTypeMapper, IConfiguration configuration)
        {
            _logger        = logger;
            _configuration = configuration;
            _dbTypeMapper  = dbTypeMapper;
            _option        = options?.Value;
            if (_option == null)
            {
                _option = new MysqlOption();
            }
            UpdateFromEnv(_option);
            if (_option.DbTables == null || !_option.DbTables.Any())
            {
                throw new ArgumentNullException(nameof(MysqlOption.DbTables));
            }

            _logger.LogInformation($"Mysql Produce Listening: {string.Join(",", _option.DbTables)}");
        }
Beispiel #4
0
        public MysqlHandler(ILogger <MysqlHandler> logger, IOptions <MysqlOption> options, IDbTransfer dbTypeMapper, IConfiguration configuration)
        {
            _logger        = logger;
            _configuration = configuration;
            _dbTypeMapper  = dbTypeMapper;
            _option        = options?.Value;
            if (_option == null)
            {
                _option = new MysqlOption();
            }

            if (_option.DbTables == null)
            {
                _option.DbTables = new List <string>();
            }

            UpdateFromEnv(_option);

            _logger.LogInformation(_option.DbTables.Any()
                ? $"Mysql Produce Listening: {string.Join(",", _option.DbTables)}"
                : $"Mysql Produce Listening");
        }
Beispiel #5
0
        public ConsumerService(ILogger <ConsumerService> logger, IOptions <RabitMqOption> rabitMqOption, IConfiguration configuration, IDbTransfer dbTypeMapper)
        {
            _logger        = logger;
            _configuration = configuration;
            _dbTypeMapper  = dbTypeMapper;
            _rabitMqOption = rabitMqOption.Value;
            if (_rabitMqOption == null)
            {
                _rabitMqOption = new RabitMqOption();
            }

            UpdateFromEnv(_rabitMqOption);

            if (string.IsNullOrEmpty(_rabitMqOption.Host) || string.IsNullOrEmpty(_rabitMqOption.UserName) ||
                string.IsNullOrEmpty(_rabitMqOption.Password) || _rabitMqOption.Port < 1 || string.IsNullOrEmpty(_rabitMqOption.CanalDestinationName))
            {
                throw new ArgumentNullException("Rabit param in appsettings.json is not correct!");
            }

            if (!_rabitMqOption.DbTables.Any())
            {
                throw new ArgumentNullException("no dbTables exist in appsettings.json !");
            }
        }