public static IDictionary <string, object> ConstructConfig(this EventConsumerOptions options) =>
 new Dictionary <string, object>
 {
     { "group.id", options.GroupId },
     { "enable.auto.commit", options.AutoCommit },
     { "auto.commit.interval.ms", options.CommitIntervalMilliseconds },
     { "statistics.interval.ms", options.StatisticsIntervalMilliseconds },
     { "bootstrap.servers", string.Join(",", options.Brokers) },
     { "default.topic.config", new Dictionary <string, object>()
       {
           { "auto.offset.reset", "smallest" }
       } }
 };
示例#2
0
        public EventConsumer(IMessageHandler messageHandler, EventConsumerOptions options, ILogger logger)
        {
            _messageHandler = messageHandler;
            _logger         = logger;

            _consumer = new Consumer <string, string>(
                options.ConstructConfig(),
                new StringDeserializer(Encoding.UTF8),
                new StringDeserializer(Encoding.UTF8));

            _consumer.OnMessage += _messageHandler.OnMessage;

            _consumer.OnStatistics         += Consumer_OnStatistics;
            _consumer.OnPartitionsRevoked  += Consumer_OnPartitionsRevoked;
            _consumer.OnPartitionsAssigned += Consumer_OnPartitionsAssigned;
            _consumer.OnPartitionEOF       += Consumer_OnPartitionEOF;
            _consumer.OnOffsetsCommitted   += Consumer_OnOffsetsCommitted;
            _consumer.OnLog          += Consumer_OnLog;
            _consumer.OnError        += Consumer_OnError;
            _consumer.OnConsumeError += Consumer_OnConsumeError;
        }