Reputation: 111
Using the Java Kafka Streams API. I want to select a new key for a topic I'm consuming. The new key will be of a different type. When I use the console consumer to consume the topic with the new key, I can only see the values.
valueStream
.map((key, value) -> new KeyValue(value.getBook_id(), value))
.peek((key, value) -> {
System.out.println("key: " + key); // prints key as expected
System.out.println("value: " + value); // prints value as expected
})
.to("foobartopic",
Produced.with(Serdes.Integer(),bookValueIntSerde));
Result of consuming "foobartopic"
The expected result is the same but with a non blank key.
Upvotes: 1
Views: 733
Reputation: 6593
Your producer uses Serdes.Integer
for key serialization, so to print key in user friendly format by kafka-console-consumer
you have to set --key-deserializer
to appropriate value. In your case it is org.apache.kafka.common.serialization.IntegerDeserializer
.
./kafka/bin//kafka-console-consumer.sh --bootstrap-server :9092 --property print.key=true --from-beginning --topic foobartopic --key-deserializer=org.apache.kafka.common.serialization.IntegerDeserializer
Upvotes: 2