【发布时间】:2018-04-25 14:10:00
【问题描述】:
我正在尝试使用 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)))
【问题讨论】: