Camel Kafka:无法阅读来自Kafka主题的消息

时间:2020-06-16 12:38:15

标签: java apache-kafka apache-camel

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

我尝试使用骆驼kafka 2.14.3来使用Java应用程序中的消息。这是我的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,它消耗得很好。但是我必须在生产中使用骆驼kafka 2.14.3。我是否缺少任何依赖项或使用了错误的URI?

1 个答案:

答案 0 :(得分:0)

我认为您在your first question中走的路正确。我非常惊讶Camel Kafka的URI格式在2.14.2和较新版本的Camel 2.x之间进行了很大的更改。也许是因为更新了Kafka版本?

您可以在version 2.24.3version 2.14.3KafkaConfiguration文档中看到它。在2.14.3版上,没有获取brokers参数的getBrokers方法,因此,您得到的错误消息是根据您使用的版本而定的。

相反,在2.24.3版本中有这样一种方法,因此它对应于较新的Camel 2.x版本的component documentation

不幸的是,我没有找到版本2.14.3的组件文档,但是也许您可以使用可能的参数KafkaConfiguration从第一个问题的URI构造它。