kmcclellan / kafka-di

An extension of Confluent's Kafka client for use with Microsoft.Extensions.DependencyInjection (and friends).
https://www.nuget.org/packages/Confluent.Kafka.DependencyInjection
MIT License
13 stars 5 forks source link

Di constructor not recognizing Ignore type in IProducer<Ignore, string> #1

Closed lbilodeau closed 3 years ago

lbilodeau commented 3 years ago

I've tried to follow your example in the readme.md file but when I run my code I get the following exception:

System.ArgumentNullException: Value cannot be null. (Parameter 'Key serializer not specified and there is no default serializer defined for type Ignore.') at Confluent.Kafka.Producer2.InitializeSerializers(ISerializer1 keySerializer, ISerializer1 valueSerializer, IAsyncSerializer1 asyncKeySerializer, IAsyncSerializer`1 asyncValueSerializer)

This error comes from the service constructor below:

public ContractManagementController( IAsyncLoggerClient logstashlogger, IConfiguration iConfig, ICluster cluster, IProducer<Ignore, string> kafkaProducer ) { _configuration = iConfig; _logstashlogger = logstashlogger; // need to pass the DI components down the workflow chain to the DAL layer BRules = new CMBR( _logstashlogger, cluster, iConfig, kafkaProducer); _logstashlogger.InitLogger(_configuration.GetValue<int>("Logstash:port"), _configuration.GetValue<string>("Logstash:hostname"), LOGGER_SOURCE); }

I only need a producer at this point so later in my service I do this:

        IProducer<Ignore, string>msgProducer = kafkaProducer;

and then to produce a message...

var pubsubresults = await msgProducer.ProduceAsync("contract_updated" , new Message<Ignore, string> { Value = JsonSerializer.Serialize(JsonContract) });

kmcclellan commented 3 years ago

Hi,

Thanks for your question. The problem is the use of the Ignore type with the producer. Ignore is only supported with consumers. I realize I have an example in the README that uses that incorrectly, which I should fix!

Simply change your IProducer<Ignore, string> kafkaProducer to IProducer<Null, string> and it should work for you.

Cheers, Kyle

Update: Fixed in 7f91798