[英]Kafka Streams Materialized Store Build Error
我正在嘗試在此處構建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()));
沒有代碼示例,我不能肯定地說,但是錯誤消息非常清楚。 您要向Kafka指定密鑰為Long
類型。 但是,您的密鑰實際上是其他一些Java對象。 例如,如果您的消息帶有String鍵,則此代碼將更改為: .withKeySerde(Serdes.String())
。 檢查密鑰的類型,並為該類型指定正確的Serde
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.