示例#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;
 }