Пример #1
0
        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}.");
                }
            }
        }
Пример #2
0
 private KafkaConsumer CreateConsumer(SubscriptionConfiguration config)
 {
     return(new KafkaConsumer(
                _observerFactoryResolver.Resolve(config),
                config.Serializer,
                config.Settings,
                _loggerFactory));
 }
Пример #3
0
        public EndpointConfiguration AddSubscription(SubscriptionConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            _subscriptions.Add(config);

            return(this);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
 public ObserverFactory(SubscriptionConfiguration configuration, IEventHandlerFactory eventHandlerFactory)
 {
     _configuration       = configuration;
     _eventHandlerFactory = eventHandlerFactory;
 }