[英]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.