示例#1
0
        public KafkaProducer(Dictionary <string, object> config,
                             Action <string> logger)
        {
            if (logger == null)
            {
                throw new Exception("Empty handler");
            }

            _logger = logger;
            _config = config;

            _genericRecordConfig = new RecordConfig((string)_config[KafkaPropNames.SchemaRegistryUrl]);
            RecordSchema         = _genericRecordConfig.RecordSchema;

            _topic = (string)config[KafkaPropNames.Topic];
        }
        public KafkaConsumer(Dictionary <string, object> config,
                             Action <string, dynamic, DateTime> consumeResultHandler,
                             Action <string> logger)
        {
            if (consumeResultHandler == null || logger == null)
            {
                throw new Exception("Empty handler");
            }

            _consumeResultHandler = consumeResultHandler;
            _logger = logger;
            _config = config;

            _cts = new CancellationTokenSource();

            _genericRecordConfig = new RecordConfig((string)config[KafkaPropNames.SchemaRegistryUrl]);
            RecordSchema         = _genericRecordConfig.RecordSchema;

            _topic = (string)config[KafkaPropNames.Topic];

            _taskConsumer = StartConsumingInner();
        }