gpt4 book ai didi

apache-kafka-streams - 新构建的 KTable 不返回任何内容

转载 作者:行者123 更新时间:2023-12-04 21:04:29 26 4
gpt4 key购买 nike

我正在尝试使用 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)))

最佳答案

经过大量研究,我发现了我的语法问题。我使用的语法是有效的,基于 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 文档

关于apache-kafka-streams - 新构建的 KTable 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50024465/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com