/// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class.
        /// </summary>
        /// <param name="configuration">The cache manager configuration.</param>
        /// <param name="loggerFactory">The logger factory</param>
        public RedisCacheBackPlate(CacheManagerConfiguration configuration, ILoggerFactory loggerFactory)
            : base(configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(loggerFactory, nameof(loggerFactory));

            this.logger      = loggerFactory.CreateLogger(this);
            this.channelName = configuration.BackPlateChannelName ?? "CacheManagerBackPlate";
            this.identifier  = Guid.NewGuid().ToString();

            var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey);

            this.connection = new RedisConnectionManager(
                cfg,
                loggerFactory);

            RetryHelper.Retry(() => this.Subscribe(), configuration.RetryTimeout, configuration.MaxRetries, this.logger);
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheBackplane"/> class.
        /// </summary>
        /// <param name="configuration">The cache manager configuration.</param>
        /// <param name="loggerFactory">The logger factory</param>
        public RedisCacheBackplane(ICacheManagerConfiguration configuration, ILoggerFactory loggerFactory)
            : base(configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(loggerFactory, nameof(loggerFactory));

            _logger      = loggerFactory.CreateLogger(this);
            _channelName = configuration.BackplaneChannelName ?? "CacheManagerBackplane";
            _identifier  = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());

            var cfg = RedisConfigurations.GetConfiguration(ConfigurationKey);

            _connection = new RedisConnectionManager(
                cfg,
                loggerFactory);

            RetryHelper.Retry(() => Subscribe(), configuration.RetryTimeout, configuration.MaxRetries, _logger);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheBackplane"/> class.
        /// </summary>
        /// <param name="configuration">The cache manager configuration.</param>
        /// <param name="loggerFactory">The logger factory</param>
        public RedisCacheBackplane(ICacheManagerConfiguration configuration, ILoggerFactory loggerFactory)
            : base(configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(loggerFactory, nameof(loggerFactory));

            _logger      = loggerFactory.CreateLogger(this);
            _channelName = configuration.BackplaneChannelName ?? "CacheManagerBackplane";
            _identifier  = Encoding.UTF8.GetBytes(Guid.NewGuid().ToString());

            var cfg = RedisConfigurations.GetConfiguration(ConfigurationKey);

            _connection = new RedisConnectionManager(
                cfg,
                loggerFactory);

            RetryHelper.Retry(() => Subscribe(), configuration.RetryTimeout, configuration.MaxRetries, _logger);

            // adding additional timer based send message invoke (shouldn't do anything if there are no messages,
            // but in really rare race conditions, it might happen messages do not get send if SendMEssages only get invoked through "NotifyXyz"
            _timer = new Timer(SendMessages, true, 1000, 1000);
        }
Exemple #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class.
        /// </summary>
        /// <param name="configuration">The cache manager configuration.</param>
        public RedisCacheBackPlate(CacheManagerConfiguration configuration)
            : base(configuration)
        {
            NotNull(configuration, nameof(configuration));

            this.channelName = configuration.BackPlateChannelName ?? "CacheManagerBackPlate";
            this.identifier  = Guid.NewGuid().ToString();

            RetryHelper.Retry(
                () =>
            {
                // throws an exception if not found for the name
                var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey);

                var connection = RedisConnectionPool.Connect(cfg);

                this.redisSubscriper = connection.GetSubscriber();
            },
                configuration.RetryTimeout,
                configuration.MaxRetries);

            this.Subscribe();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RedisCacheBackPlate"/> class.
        /// </summary>
        /// <param name="configuration">The cache manager configuration.</param>
        /// <param name="loggerFactory">The logger factory</param>
        public RedisCacheBackPlate(CacheManagerConfiguration configuration, ILoggerFactory loggerFactory)
            : base(configuration)
        {
            NotNull(configuration, nameof(configuration));
            NotNull(loggerFactory, nameof(loggerFactory));

            this.logger      = loggerFactory.CreateLogger(this);
            this.channelName = configuration.BackPlateChannelName ?? "CacheManagerBackPlate";
            this.identifier  = Guid.NewGuid().ToString();

            var cfg = RedisConfigurations.GetConfiguration(this.ConfigurationKey);

            this.connection = new RedisConnectionManager(
                cfg,
                loggerFactory);

            RetryHelper.Retry(() => this.Subscribe(), configuration.RetryTimeout, configuration.MaxRetries, logger);

            this.timer = new Timer(
                (obj) =>
            {
                if (this.sending)
                {
                    return;
                }

                lock (this.messageLock)
                {
                    try
                    {
                        this.sending = true;
                        if (this.messages != null && this.messages.Count > 0)
                        {
                            var msgs = string.Join(",", this.messages);
                            if (this.logger.IsEnabled(LogLevel.Debug))
                            {
                                this.logger.LogDebug("Back-plate is sending {0} messages ({1} skipped).", this.messages.Count, this.skippedMessages);
                            }

                            RetryHelper.Retry(
                                () =>
                            {
                                this.Publish(msgs);
                            },
                                configuration.RetryTimeout,
                                configuration.MaxRetries,
                                this.logger);

                            this.skippedMessages = 0;
                            this.messages.Clear();
                        }
                    }
                    catch (Exception ex)
                    {
                        this.logger.LogError(ex, "Error occurred sending back plate messages.");
                    }
                    finally
                    {
                        this.sending = false;
                    }
                }
            },
                this,
                TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100));
        }