コード例 #1
0
 public void SetConsumerEventsHandlers(
     KafkaConsumer ownerConsumer,
     IConfluentConsumerBuilder consumerBuilder) =>
 consumerBuilder
 .SetStatisticsHandler(OnConsumerStatistics)
 .SetPartitionsAssignedHandler((consumer, list) => OnPartitionsAssigned(ownerConsumer, consumer, list))
 .SetPartitionsRevokedHandler((consumer, list) => OnPartitionsRevoked(ownerConsumer, consumer, list))
 .SetOffsetsCommittedHandler(OnOffsetsCommitted)
 .SetErrorHandler((_, error) => OnConsumerError(ownerConsumer, error));
コード例 #2
0
 public static void SetEventsHandlers(
     this IConfluentConsumerBuilder consumerBuilder,
     KafkaConsumer consumer,
     ISilverbackIntegrationLogger logger) =>
 consumerBuilder
 .SetStatisticsHandler((_, statistics) => OnStatistics(statistics, consumer, logger))
 .SetPartitionsAssignedHandler((_, partitions) => OnPartitionsAssigned(partitions, consumer, logger))
 .SetPartitionsRevokedHandler((_, partitions) => OnPartitionsRevoked(partitions, consumer, logger))
 .SetOffsetsCommittedHandler((_, offsets) => OnOffsetsCommitted(offsets, consumer, logger))
 .SetErrorHandler((_, error) => OnError(error, consumer, logger))
 .SetLogHandler((_, logMessage) => OnLog(logMessage, consumer, logger));
コード例 #3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="KafkaConsumer" /> class.
        /// </summary>
        /// <param name="broker">
        ///     The <see cref="IBroker" /> that is instantiating the consumer.
        /// </param>
        /// <param name="endpoint">
        ///     The endpoint to be consumed.
        /// </param>
        /// <param name="behaviorsProvider">
        ///     The <see cref="IBrokerBehaviorsProvider{TBehavior}" />.
        /// </param>
        /// <param name="serviceProvider">
        ///     The <see cref="IServiceProvider" /> to be used to resolve the needed services.
        /// </param>
        /// <param name="logger">
        ///     The <see cref="ISilverbackIntegrationLogger" />.
        /// </param>
        public KafkaConsumer(
            KafkaBroker broker,
            KafkaConsumerEndpoint endpoint,
            IBrokerBehaviorsProvider <IConsumerBehavior> behaviorsProvider,
            IServiceProvider serviceProvider,
            ISilverbackIntegrationLogger <KafkaConsumer> logger)
            : base(broker, endpoint, behaviorsProvider, serviceProvider, logger)
        {
            Check.NotNull(endpoint, nameof(endpoint));
            Check.NotNull(serviceProvider, nameof(serviceProvider));

            _confluentConsumerBuilder = serviceProvider.GetRequiredService <IConfluentConsumerBuilder>();
            _confluentConsumerBuilder.SetConfig(endpoint.Configuration.ConfluentConfig);

            _kafkaEventsHandler = serviceProvider.GetRequiredService <KafkaEventsHandler>();
            _kafkaEventsHandler.SetConsumerEventsHandlers(this, _confluentConsumerBuilder);

            _logger = Check.NotNull(logger, nameof(logger));
        }