简体   繁体   English

Kafka Streams物化商店构建错误

[英]Kafka Streams Materialized Store Build Error

I'm trying to build the Materialized.as DSL code here: https://kafka.apache.org/11/javadoc/org/apache/kafka/streams/state/Stores.html 我正在尝试在此处构建Materialized.as DSL代码: https : //kafka.apache.org/11/javadoc/org/apache/kafka/streams/state/Stores.html

But I'm getting the error 但是我得到了错误

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

On the line 在线上

.withKeySerde(Serdes.Long())

Does anyone know what might be wrong here? 有人知道这里可能出什么问题吗?

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()));

The problem is that builder.table does not know the generic type defaulting to <Object,Object> . 问题是builder.table不知道默认为<Object,Object>的泛型类型。 Later, the Serde types don't match. 后来,Serde类型不匹配。 You need to specify the types like 您需要指定类似的类型

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

I cannot say for sure without a code sample, however the error message is very clear. 没有代码示例,我不能肯定地说,但是错误消息非常清楚。 You are specifying to Kafka that the key is of type Long . 您要向Kafka指定密钥为Long类型。 However your key is actually some other Java Object. 但是,您的密钥实际上是其他一些Java对象。 For example if you had a message with a String key, this code would change to: .withKeySerde(Serdes.String()) . 例如,如果您的消息带有String键,则此代码将更改为: .withKeySerde(Serdes.String()) Check the type of the key and specify the correct Serde for that type. 检查密钥的类型,并为该类型指定正确的Serde

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM