Kafka Streams:java.lang.IllegalArgumentException:VoidDeserializer 的数据应为 null
我正在处理我的 Kafka Streams 的第一个示例:
package com.example;
import java.util.Properties;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.KafkaStreams;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.kstream.KStream;
class DslExample {
public static void main(String[] args) {
// the builder is used to construct the topology
StreamsBuilder builder = new StreamsBuilder();
// read from the source topic, "users"
KStream<Void, String> stream = builder.stream("users");
// for each record that appears in the source topic,
// print the value
stream.foreach(
(key, value) -> {
System.out.println("(DSL) Hello, " + value);
});
// you can also print using the `print` operator
// stream.print(Printed.<String, String>toSysOut().withLabel("source"));
// set the required properties for running Kafka Streams
Properties config = new Properties();
config.put(StreamsConfig.APPLICATION_ID_CONFIG, "dev1");
config.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "10.0.0.24:29092");
config.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
config.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.Void().getClass());
config.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
// build the topology and start streaming
KafkaStreams streams = new KafkaStreams(builder.build(), config);
streams.start();
// close Kafka Streams when the JVM shuts down (e.g. SIGTERM)
Runtime.getRuntime().addShutdownHook(new Thread(streams::close));
}
}
当我尝试运行它时,我收到此错误:
Caused by: java.lang.IllegalArgumentException: Data should be null for a VoidDeserializer.
这是来自“用户”主题的示例消息:
值:
{
"registertime": 1517518703752,
"userid": "User_8",
"regionid": "Region_7",
"gender": "OTHER"
}
标头:
[
{
"key": "task.generation",
"stringValue": "0"
},
{
"key": "task.id",
"stringValue": "0"
},
{
"key": "current.iteration",
"stringValue": "86144"
}
]
键:
User_8
我应该做什么来避免此问题?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果密钥实际上有数据,则不应使用
Serdes.Void()
或KStream
If the key actually has data, you shouldn't be using
Serdes.Void()
orKStream<Void,
将 Void 更改为 String 将使流在示例中工作
Changing Void to String will make the stream work in the example