Just fyi, you can specify keys as well as values with kafka-console-producer. Try adding the properties
--property parse.key=true --property key.separator=, to your invocation. You can then specify messages as key,value from stdin (For kaka-console-consumer, the related properties are print.key and key.separator.) --- Ian Wrigley Director, Education Services Confluent, Inc > On Jun 16, 2016, at 5:58 AM, Adrienne Kole <adrienneko...@gmail.com> wrote: > > Thank you for your answers. I was trying to give input to topic from > console. Therefore, when I consume the message on kafka streams, I got > values with null keys. When I used producer classes of kafka as a > Producer, I managed to solve the problem. > > Thank you for your guidance. > > Adrienne. > > On Thu, Jun 16, 2016 at 10:57 AM, Matthias J. Sax <matth...@confluent.io> > wrote: > >> On small addition: >> >> If your input topic does not have any key specified, you can still >> extract a key from the value >> >> KTable source = builder.stream(...).selectKey(...).toTable(...) >> >> >> -Matthias >> >> On 06/15/2016 08:30 PM, Eno Thereska wrote: >>> Hi Adrienne, >>> >>> How do you enter the input on t1 topic? If using kafka-console-producer, >> you'll need to pass in keys as well as values. Here is an example: >> http://www.shayne.me/blog/2015/2015-06-25-everything-about-kafka-part-2/ < >> http://www.shayne.me/blog/2015/2015-06-25-everything-about-kafka-part-2/> >>> >>> Thanks >>> Eno >>> >>>> On 15 Jun 2016, at 17:21, Adrienne Kole <adrienneko...@gmail.com> >> wrote: >>>> >>>> Hi community, >>>> >>>> Probably it is very basic question, as I am new to Kafka Streams. >>>> I am trying to initialize KTable or KStream from kafka topic. However, >> I >>>> don't know how to avoid getting null keys. So, >>>> >>>> KTable<String, String> source = >>>> builder.stream(Serdes.String(),Serdes.String(),"t1"); >>>> source.print(); >>>> >>>> I enter the input on t1 topic as: >>>> >>>> one >>>> two >>>> one one >>>> >>>> and get as a result: >>>> >>>> null, (one <-null) >>>> null, (two <-null) >>>> null, (one one <-null) >>>> >>>> >>>> So, the key is always null. >>>> >>>> Is the key supposed to initialize after getting input from topic? If >> yes, >>>> how can I initialize key in KTable after getting input? For example in >>>> KStream we have KeyValueMapper that can be used to assign new keys and >>>> values. However, in KTable we have only ValueMappers. >>>> >>>> If not, how can I initialize the key of KTable from the input from >> given >>>> topic? >>>> >>>> >>>> Cheers >>>> Adrienne >>> >>> >> >>