public EndToEndTests(ITestOutputHelper outputHelper) { _outputHelper = outputHelper; _producerBuilder = ProducerBuilder.Empty.UseRedisProducerChannel( _testScopeCancellation /*, * configuration: (cfg) => cfg.ServiceName = "mymaster" */); var consumerSetting = RedisConsumerChannelSetting.Default; var claimTrigger = consumerSetting.ClaimingTrigger; claimTrigger.EmptyBatchCount = 5; claimTrigger.MinIdleTime = TimeSpan.FromSeconds(3); consumerSetting.DelayWhenEmptyBehavior.CalcNextDelay = d => TimeSpan.FromMilliseconds(2); _consumerBuilder = ConsumerBuilder.Empty.UseRedisConsumerChannel( _testScopeCancellation /*, * configuration: (cfg) => cfg.ServiceName = "mymaster" */, claimingTrigger: claimTrigger); A.CallTo(() => _subscriber.RegisterAsync(A <User> .Ignored)) .ReturnsLazily(() => ValueTaskStatic.CompletedValueTask); A.CallTo(() => _subscriber.LoginAsync(A <string> .Ignored, A <string> .Ignored)) .ReturnsLazily(() => Delay()); A.CallTo(() => _subscriber.EarseAsync(A <int> .Ignored)) .ReturnsLazily(() => Delay()); #region A.CallTo(() => _fakeLogger...) A.CallTo(() => _fakeLogger.Log <string>( A <LogLevel> .Ignored, A <EventId> .Ignored, A <string> .Ignored, A <Exception> .Ignored, A <Func <string, Exception, string> > .Ignored )) .Invokes <object, LogLevel, EventId, string, Exception, Func <string, Exception, string> >((level, id, msg, ex, fn) => _outputHelper.WriteLine( $"Info: {fn(msg, ex)}")); #endregion // A.CallTo(() => _fakeLogger...) async ValueTask Delay() => await Task.Delay(200); }
/// <summary> /// Uses REDIS consumer channel. /// </summary> /// <param name="builder">The builder.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="setting">The setting.</param> /// <param name="logger">The logger.</param> /// <param name="endpointEnvKey">The endpoint env key.</param> /// <param name="passwordEnvKey">The password env key.</param> /// <returns></returns> public static IConsumerOptionsBuilder UseRedisConsumerChannel( this IConsumerBuilder builder, CancellationToken cancellationToken, RedisConsumerChannelSetting?setting = null, ILogger?logger = null, string endpointEnvKey = CONSUMER_END_POINT_KEY, string passwordEnvKey = CONSUMER_PASSWORD_KEY) { var cfg = setting ?? RedisConsumerChannelSetting.Default; var channel = new RedisConsumerChannel( logger ?? EventSourceFallbakLogger.Default, cfg, endpointEnvKey, passwordEnvKey); cancellationToken.ThrowIfCancellationRequested(); IConsumerOptionsBuilder result = builder.UseChannel(channel); return(result); }