protected void SetConsumerAndExecutor(IAsyncDeserializer <TValue> asyncValueDeserializer, IDeserializer <TValue> valueDeserializer, IAsyncDeserializer <TKey> keyDeserializer) { consumer = CreateConsumer( config: GetConsumerConfiguration(), errorHandler: (_, e) => { logger.LogError(e.Reason); }, partitionsAssignedHandler: (_, e) => { logger.LogInformation($"Assigned partitions: [{string.Join(", ", e)}]"); }, partitionsRevokedHandler: (_, e) => { logger.LogInformation($"Revoked partitions: [{string.Join(", ", e)}]"); }, asyncValueDeserializer: asyncValueDeserializer, valueDeserializer: valueDeserializer, keyDeserializer: keyDeserializer); functionExecutor = singleDispatch ? (FunctionExecutorBase <TKey, TValue>) new SingleItemFunctionExecutor <TKey, TValue>(executor, consumer, options.ExecutorChannelCapacity, options.ChannelFullRetryIntervalInMs, logger) : new MultipleItemFunctionExecutor <TKey, TValue>(executor, consumer, options.ExecutorChannelCapacity, options.ChannelFullRetryIntervalInMs, logger); consumer.Subscribe(topic); // Using a thread as opposed to a task since this will be long running // https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#avoid-using-taskrun-for-long-running-work-that-blocks-the-thread var thread = new Thread(ProcessSubscription) { IsBackground = true, }; thread.Start(cancellationTokenSource.Token); }
public Task StartAsync(CancellationToken cancellationToken) { var builder = this.CreateConsumerBuilder(GetConsumerConfiguration()); builder.SetErrorHandler((_, e) => { logger.LogError(e.Reason); }) .SetPartitionsAssignedHandler((_, e) => { logger.LogInformation($"Assigned partitions: [{string.Join(", ", e)}]"); }) .SetPartitionsRevokedHandler((_, e) => { logger.LogInformation($"Revoked partitions: [{string.Join(", ", e)}]"); }); if (valueDeserializer != null) { if (valueDeserializer is IAsyncDeserializer <TValue> asyncValueDeserializer) { builder.SetValueDeserializer(asyncValueDeserializer); } else if (valueDeserializer is IDeserializer <TValue> syncValueDeserializer) { builder.SetValueDeserializer(syncValueDeserializer); } else { throw new InvalidOperationException($"Value deserializer must implement either IAsyncDeserializer or IDeserializer. Type {valueDeserializer.GetType().Name} does not"); } } this.consumer = builder.Build(); var commitStrategy = new AsyncCommitStrategy <TKey, TValue>(consumer, this.logger); functionExecutor = singleDispatch ? (FunctionExecutorBase <TKey, TValue>) new SingleItemFunctionExecutor <TKey, TValue>(executor, consumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger) : new MultipleItemFunctionExecutor <TKey, TValue>(executor, consumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger); consumer.Subscribe(this.listenerConfiguration.Topic); // Using a thread as opposed to a task since this will be long running // https://github.com/davidfowl/AspNetCoreDiagnosticScenarios/blob/master/AsyncGuidance.md#avoid-using-taskrun-for-long-running-work-that-blocks-the-thread var thread = new Thread(ProcessSubscription) { IsBackground = true, }; thread.Start(cancellationTokenSource.Token); return(Task.CompletedTask); }
public Task StartAsync(CancellationToken cancellationToken) { AzureFunctionsFileHelper.InitializeLibrdKafka(this.logger); var builder = this.CreateConsumerBuilder(GetConsumerConfiguration()); builder.SetErrorHandler((_, e) => { logger.LogError(e.Reason); }) .SetPartitionsAssignedHandler((_, e) => { logger.LogInformation($"Assigned partitions: [{string.Join(", ", e)}]"); }) .SetPartitionsRevokedHandler((_, e) => { logger.LogInformation($"Revoked partitions: [{string.Join(", ", e)}]"); }); if (ValueDeserializer != null) { builder.SetValueDeserializer(ValueDeserializer); } this.consumer = builder.Build(); var commitStrategy = new AsyncCommitStrategy <TKey, TValue>(consumer, this.logger); functionExecutor = singleDispatch ? (FunctionExecutorBase <TKey, TValue>) new SingleItemFunctionExecutor <TKey, TValue>(executor, consumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger) : new MultipleItemFunctionExecutor <TKey, TValue>(executor, consumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger); consumer.Subscribe(this.listenerConfiguration.Topic); // Using a thread as opposed to a task since this will be long running var thread = new Thread(ProcessSubscription) { IsBackground = true, }; thread.Start(cancellationTokenSource.Token); return(Task.CompletedTask); }
public Task StartAsync(CancellationToken cancellationToken) { var localConsumer = this.consumer.Value; var commitStrategy = new AsyncCommitStrategy <TKey, TValue>(localConsumer, this.logger); this.functionExecutor = singleDispatch ? (FunctionExecutorBase <TKey, TValue>) new SingleItemFunctionExecutor <TKey, TValue>(executor, localConsumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger) : new MultipleItemFunctionExecutor <TKey, TValue>(executor, localConsumer, this.options.ExecutorChannelCapacity, this.options.ChannelFullRetryIntervalInMs, commitStrategy, logger); localConsumer.Subscribe(this.listenerConfiguration.Topic); // Using a thread as opposed to a task since this will be long running var thread = new Thread(ProcessSubscription) { IsBackground = true, }; thread.Start(cancellationTokenSource.Token); return(Task.CompletedTask); }