新建KTable什么都不返回

时间:2018-04-25 14:10:01

标签: apache-kafka-streams

我正在尝试使用KTable来消费来自Kafka主题的事件。但是,它什么也没有回报。当我使用KStream时,它返回并打印对象。这真的很奇怪。 Producer and Consumer can be found here

//Not working    
KTable<String, Customer> customerKTable = streamsBuilder.table("customer", Consumed.with(Serdes.String(), customerSerde),Materialized.<String, Customer, KeyValueStore<Bytes, byte[]>>as(customerStateStore.name()));
customerKTable.foreach(((key, value) -> System.out.println("Customer from Topic: " + value)));

//KStream working
KStream<String, Customer> customerKStream= streamsBuilder.stream("customer", Consumed.with(Serdes.String(), customerSerde));
customerKStream.foreach(((key, value) -> System.out.println("Customer from Topic: " + value)))

1 个答案:

答案 0 :(得分:2)

经过大量研究后,我在语法中发现了这个问题。我使用的语法是有效的,基于Confluent / Kafka文档,但它不起作用。将与Kafka团队提出一个错误。现在,正在运行的新语法是

KTable<String, Customer> customerKTable = streamsBuilder.table("customer",Materialized.<String, Customer, KeyValueStore<Bytes, byte[]>>as(customerStateStore.name())
                                                            .withKeySerde(Serdes.String())
                                                            .withValueSerde(customerSerde));

我应该包含withKeySerde()withValueSerde()来制作KTable。但是没有提到Confluent / Kafka文档