The confluent kafka documentation says, a Consumer class is defined as follows:
Class Consumer<TKey, TValue>
The consumer class above implements a high-level Apache Kafka consumer (with key and value deserialization).
I understand the TKey and TValue are for deserializing the key, which is sent in from the producer. For example, something like
Sending in a key from the producer would look as
var deliveryReport = producer.ProduceAsync(topicName, key, val);
Receiving the string key on the consumer end would look as
using (var consumer = new Consumer<Ignore, string>(constructConfig(brokerList, false), null, new StringDeserializer(Encoding.UTF8)))
{
consumer.Subscribe(topics);
Console.WriteLine($"Started consumer, Ctrl-C to stop consuming");
var cancelled = false;
Console.CancelKeyPress += (_, e) => {
e.Cancel = true; // prevent the process from terminating.
cancelled = true;
};
while (!cancelled)
{
Message<Ignore, string> msg;
if (!consumer.Consume(out msg, TimeSpan.FromMilliseconds(100)))
{
continue;
}
Console.WriteLine($"Topic: {msg.Topic} Partition: {msg.Partition} Offset: {msg.Offset} {msg.Value}");
}
}
Since we are passing in a key, the Consumer is initialized as
Consumer<Ignore, string>
and the message is initialized as
Message<Ignore, String>
After all that, my question is, what does deserialization of the key really mean? And why do we need to do that? Also, why do we need to pass in a key-value pair Ignore, String for performing deserialization?