apache-kafka - 从命令提示符启动 Kafka 消费者时,我收到 Class Not Found Exception。我该如何解决这个问题?
问题描述
我正在使用 Kafka-streams 执行字数统计问题。Kafka 使用的版本是 2.3.1,创建了 word-count-input 和 word-count-output 两个主题。相同的代码是
public static void main( String[] args )
{
Properties properties = new Properties();
properties.put(StreamsConfig.APPLICATION_ID_CONFIG, "word-count");
properties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
properties.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
properties.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass());
properties.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass());
StreamsBuilder builder = new StreamsBuilder();
KStream<String, String> textLines = builder.stream("word-count-input");
KTable<String, Long> wordCounts = textLines.mapValues(value -> value.toLowerCase())
.flatMapValues(value -> Arrays.asList(value.split(" ")))
.selectKey((key,value) -> value)
.groupByKey()
.count();
// Writing back to the kafka topic
wordCounts.toStream().to("word-count-output", Produced.with(Serdes.String(), Serdes.Long()));
KafkaStreams streams = new KafkaStreams(builder.build(), properties);
streams.start();
//printing the topology
System.out.println(streams.toString());
// shutdown hook to correctly close the stream application
Runtime.getRuntime().addShutdownHook(new Thread(streams::close));
}
在使用命令提示符启动主题字数输出的消费者时,它会抛出 Class Not Found Exception 以设置 key.deserializer 和 value.deserializer 的属性。
您可以在此处查看命令提示符。
解决方案
问题在于 Kafka 版本的不同。系统上安装的版本是2.3.1,maven里安装的是2.1.1。希望它可以帮助某人。
推荐阅读
- angular - 如何使用 jasmine spy 为 window.location.pathname 编写单元测试?
- java - DB2 外部 java jar 文件存储过程错误
- spfx - 如何使用@pnp/sp查询SP列表中的person列获取姓名
- docker - 如何使用 kubernetes env 访问容器环境变量?
- excel - 日期不按年份分组的 Excel 数据透视表
- node.js - npm 脚本无法在 docker 容器的 workdir 中找到文件
- bash - 错误:“用户”指令仅在主进程以超级用户权限运行时才有意义
- c# - 如何在 Visual Studio 中启用自动填充选项
- c++ - 强制引用类型
- c# - .NET Core 两次调用异步视图?