Example #1
0
        /// <summary>
        /// Subscribe to the channel for specific metadata.
        /// </summary>
        /// <param name="plan">The consumer plan.</param>
        /// <param name="func">The function.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// When completed
        /// </returns>
        public async ValueTask SubsribeAsync(
            IConsumerPlan plan,
            Func <Announcement, IAck, ValueTask> func,
            IEventSourceConsumerOptions options,
            CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            { // connection errors
                IDatabaseAsync db = await _redisClientFactory.GetDbAsync();

                if (plan.Shard != string.Empty)
                {
                    await SubsribeShardAsync(db, plan, func, options, cancellationToken);
                }
                else
                {
                    await SubsribePartitionAsync(db, plan, func, options, cancellationToken);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="resiliencePolicy">The resilience policy for retry.</param>
        /// <param name="endpointEnvKey">The endpoint env key.</param>
        /// <param name="passwordEnvKey">The password env key.</param>
        public RedisProducerChannel(
            ILogger logger,
            Action <ConfigurationOptions>?configuration,
            AsyncPolicy?resiliencePolicy,
            string endpointEnvKey,
            string passwordEnvKey)
        {
            _logger           = logger;
            _resiliencePolicy = resiliencePolicy ??
                                Policy.Handle <Exception>()
                                .RetryAsync(3);       // TODO: [bnaya 2021-02] onRetry -> open telemetry
            string name = string.Format(
                CONNECTION_NAME_PATTERN,
                Interlocked.Increment(ref _index));
            var redisClientFactory = new RedisClientFactory(
                logger,
                name,
                RedisUsageIntent.Write,
                configuration,
                endpointEnvKey, passwordEnvKey);

            _dbTask = redisClientFactory.GetDbAsync();
        }