首页 > 解决方案 > Camel Kafka:无法读取来自 Kafka 主题的消息

问题描述

我有一个 Kafka 集群(版本:0.10.1.0),有 9 个代理和 10 个分区。

我尝试使用 camel kafka 使用来自 java 应用程序的消息2.14.3。这是我的 pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-kafka</artifactId>
    <version>2.14.3</version>
</dependency>

这只是我使用的与骆驼卡夫卡相关的依赖项。下面是骆驼卡夫卡消费者代码。

<route id="ReadFromTopic">
    <from uri="kafka:[[topic]]?brokers=[[broker.list]]&amp;groupId=[[consumer.group]]" />   
    <log message="read message : ${body}" />
</route>

我正在使用文档https://camel.apache.org/components/latest/kafka-component.html中指定的 Kafka URI 。

但下面是我在加载骆驼上下文时遇到的异常

Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: kafka://[[topic]]?brokers=[[broker.list]]&groupId=[[consumer.group]] due to: Failed to resolve endpoint: kafka://[[topic]]?brokers=[[broker.list]]&groupId=[[consumer.group]] due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{brokers=[[broker.list]]}]

它说Unknown parameters=[{brokers=[[broker.list]]}]。我试过了camel-kafka 3.x,它消耗得很好。但我必须2.14.3在生产中使用骆驼卡夫卡。我是否缺少任何依赖项或使用了错误的 URI?

标签: javaapache-kafkaapache-camel

解决方案


我认为您在第一个问题中走在正确的道路上。我很惊讶 Camel Kafka 的 URI 格式在 2.14.2 和较新版本的 Camel 2.x 之间发生了如此大的变化。也许是因为较新的 Kafka 版本?

您可以在2.24.32.14.3KafkaConfiguration版本的文档中看到它。在 2.14.3 版本上,没有 getBrokers 方法来获取参数,所以你得到的错误信息是根据你使用的版本而定的。brokers

相反,在 2.24.3 版本中有这样的方法,因此它对应于较新的 Camel 2.x 版本的组件文档。

不幸的是,我没有找到 2.14.3 版本的组件文档,但也许您可以从您的第一个问题的 URI 中使用KafkaConfiguration.


推荐阅读