private async Task RunConsuming(SubscriptionConfiguration config, CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { _logger.LogInformation( $"Subscription starting. Topic {config.Settings.Topic}. Group {config.Settings.Config.GroupId}"); using var consumer = CreateConsumer(config); try { await consumer.ConsumeAsync(cancellationToken); } finally { consumer.Close(); } } catch (OperationCanceledException) { _logger.LogInformation($"Subscription stopped. Topic: {config.Settings.Topic}."); } catch (Exception ex) { _logger.LogError(ex, $"Subscription failed. Topic: {config.Settings.Topic}."); } } }
private KafkaConsumer CreateConsumer(SubscriptionConfiguration config) { return(new KafkaConsumer( _observerFactoryResolver.Resolve(config), config.Serializer, config.Settings, _loggerFactory)); }
public EndpointConfiguration AddSubscription(SubscriptionConfiguration config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } _subscriptions.Add(config); return(this); }
public EndpointConfiguration AddSubscription( ConsumerSettings settings, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEventTypes = true, int instances = 1) { var subscription = new SubscriptionConfiguration( settings, serializer, handlerConfig, skipUnknownEventTypes, instances); _subscriptions.Add(subscription); return(this); }
public EndpointConfiguration AddBatchSubscription( ConsumerSettings settings, BatchConfiguration batchConfig, IEventDeserializer serializer, HandlerConfiguration handlerConfig = default, bool skipUnknownEventTypes = true, int instances = 1, bool isLongRunning = true) { var subscription = new SubscriptionConfiguration( isLongRunning ? settings.ToLongRunning() : settings, batchConfig, serializer, handlerConfig, skipUnknownEventTypes, instances); _subscriptions.Add(subscription); return(this); }
public ObserverFactory(SubscriptionConfiguration configuration, IEventHandlerFactory eventHandlerFactory) { _configuration = configuration; _eventHandlerFactory = eventHandlerFactory; }