kafka-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amrit Jangid <jangid.ii...@gmail.com>
Subject Re: Kafka stream specify key for message
Date Thu, 14 Jun 2018 05:10:58 GMT
.to() method is called on KStream, like KStream.to(outputTopic, Produced....
),

See sample code below-

 KStream<String, String> inputStream = builder.stream("input-topic");
 KStream<String, Integer> outputStream = inputStream.map(new
KeyValueMapper<String, String, KeyValue<String, Integer>> {
     KeyValue<String, Integer> apply(String key, String value) {
         return new KeyValue<>(key.toUpperCase(), value.split(" ").length);
     }
 });


KStream contains <key,value>  And key values derived from key of
input-topic.
Is this code key is upper-case-value for input-topic keys.

You don't have to set values of the key in Produced class, it needs the
type/serde of key , eg- byteArraySerde.







On Thu, Jun 14, 2018 at 9:14 AM pradeep s <sreekumar.pradeep@gmail.com>
wrote:

> Hi,
> In kafka stream, when we use *to *method for sending values to a topic, is
> there a way to mention the message key .
>
> .to(outputTopic, Produced.with(byteArraySerde, itemEnvelopeSerde));
>
> In Produced class , i cant find a way to set the key.
>
>
> https://kafka.apache.org/10/javadoc/org/apache/kafka/streams/kstream/Produced.html
>
> Thanks
>
> Pradeep
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message