gpt4 book ai didi

java - Kafka Streams 物化存储构建错误

转载 作者:行者123 更新时间:2023-12-02 10:24:42 25 4
gpt4 key购买 nike

我正在尝试在这里构建 Materialized.as DSL 代码:https://kafka.apache.org/11/javadoc/org/apache/kafka/streams/state/Stores.html

但我收到错误

incompatible types: org.apache.kafka.common.serialization.Serde<java.lang.Long> cannot be converted to org.apache.kafka.common.serialization.Serde<java.lang.Object>

上线

.withKeySerde(Serdes.Long())

有人知道这里可能出了什么问题吗?

final StreamsBuilder builder = new StreamsBuilder();

KeyValueBytesStoreSupplier storeSupplier = Stores.inMemoryKeyValueStore("mystore");
KTable<Long,String> dataStore = builder.table(
"example_stream",
Materialized.as(storeSupplier)
.withKeySerde(Serdes.Long())
.withValueSerde(Serdes.String()));

最佳答案

问题是 builder.table不知道默认为 <Object,Object> 的泛型类型。后来,Serde 类型不匹配。您需要指定类型,例如

KTable<Long,String> dataStore = builder.<Long,String>table(
"example_stream",
Materialized.as(storeSupplier)
.withKeySerde(Serdes.Long())
.withValueSerde(Serdes.String()));

关于java - Kafka Streams 物化存储构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54062509/

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