简体   繁体   English

Kafka 中的 Serde String[]

[英]Serde String[] in Kafka

I'm new in kafka.我是卡夫卡的新手。 I am using the store builder and want to have a String[] of two elements as the value associated to the key.我正在使用商店构建器,并希望将两个元素的 String[] 作为与键关联的值。 I set up the store like this:我这样设置商店:

StoreBuilder<KeyValueStore<String, String>> storeBuilder=Stores.keyValueStoreBuilder(
                Stores.persistentKeyValueStore(storeName),
                Serdes.String(),
                Serdes.String());
builder.addStateStore(storeBuilder);

When I call the method to have the data into the store:当我调用该方法将数据放入存储时:

String []oldValues = store.get(v.getVessel());

I receive this error:我收到此错误:

Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class [Ljava.lang.String; (java.lang.String and [Ljava.lang.String; are in module java.base of loader 'bootstrap')

I should set the store like this:我应该这样设置商店:

StoreBuilder<KeyValueStore<String, String[]>>

but I don't know what to put instead of Serdes.String()但我不知道该放什么而不是 Serdes.String()

You would need to define your own Serializer, Deserializer and Serde subclasses to do this.您需要定义自己的 Serializer、Deserializer 和 Serde 子类来执行此操作。

You can simply use a plain string with JSON deserialization to create a String array, or CSV您可以简单地使用带有 JSON 反序列化的纯字符串来创建字符串数组,或者 CSV

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

相关问题 kafka 流示例引发 class 转换异常,serde windowed -&gt; string。 如何设置正确的 Serde? - kafka streams example throws a class cast exception, serde windowed -> string. How to set the proper Serde? Kafka Streams - 使用 Protobuf serde 遇到问题 - Kafka Streams - Getting issue using Protobuf serde 重新分区后,Kafka 流不使用 serde - Kafka streams not using serde after repartitioning Kafka Streams API 中的 ArrayList Serde 问题 - Issue with ArrayList Serde in Kafka Streams API Spring Cloud Stream Kafka-找不到Serde类:org.apache.kafka.common.serialization.Serde $ StringSerde - Spring Cloud Stream Kafka - Serde class not found: org.apache.kafka.common.serialization.Serde$StringSerde 在 Kafka Consumer API 中实现 Deserializer 和 Serde 有什么区别? - What is the difference between implementing Deserializer and Serde in Kafka Consumer API? 使用 Spring Cloud Stream 的 Kafka Streams 进程中的 Serde 错误 - Serde error in Kafka Streams process with Spring Cloud Stream 如何在 application.properties 中设置 default-key/value-serde - Spring Boot Kafka Streams - How can I set default-key/value-serde in application.properties - Spring Boot Kafka Streams Kafka字符串序列化效率 - Kafka string serialization efficiency 如何初始化 kafka ConsumerRecords<String,String> 在 kafka 中进行测试 - How can I initialize kafka ConsumerRecords<String,String> in kafka for testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM