使用适用于Apache Camel(版本2.19.1)的kafka组件时出错,我只是尝试在主题中打印传入的消息,我的管道是如此组成:
...
context.addRoutes(new RouteBuilder() {
public void configure() {
from("kafka://localhost:9092?topic=test&groupId=testing")
.to("stream:out");
context.start();
}
}
尝试使用和不使用" //"在端点。
我得到的是:
Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[[From[kafka://localhost:9092?topic=test&groupI... because of Brokers must be configured
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:147)
at org.apache.camel.impl.DefaultCamelContext.doWarmUpRoutes(DefaultCamelContext.java:3762)
at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(DefaultCamelContext.java:3669)
at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(DefaultCamelContext.java:3455)
at org.apache.camel.impl.DefaultCamelContext.doStartCamel(DefaultCamelContext.java:3309)
at org.apache.camel.impl.DefaultCamelContext.access$000(DefaultCamelContext.java:202)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3093)
at org.apache.camel.impl.DefaultCamelContext$2.call(DefaultCamelContext.java:3089)
at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(DefaultCamelContext.java:3112)
at org.apache.camel.impl.DefaultCamelContext.doStart(DefaultCamelContext.java:3089)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:3026)
at org.apache.camel.MainApp.main(MainApp.java:60)
Caused by: java.lang.IllegalArgumentException: Brokers must be configured
at org.apache.camel.component.kafka.KafkaConsumer.<init>(KafkaConsumer.java:62)
at org.apache.camel.component.kafka.KafkaEndpoint.createConsumer(KafkaEndpoint.java:76)
at org.apache.camel.impl.EventDrivenConsumerRoute.addServices(EventDrivenConsumerRoute.java:69)
at org.apache.camel.impl.DefaultRoute.onStartingServices(DefaultRoute.java:103)
at org.apache.camel.impl.RouteService.doWarmUp(RouteService.java:172)
at org.apache.camel.impl.RouteService.warmUp(RouteService.java:145)
... 12 more
Process finished with exit code 1
我试图解决这个问题,但我真的不明白问题是什么,我的kafka集群是一个单独的经纪人,所有人都已经开始运行(zookeeper和服务器),寻求帮助
答案 0 :(得分:2)
将brokers=localhost:9092
添加到消费者uri。
答案 1 :(得分:0)
查看this example网址的第一部分是topic
,然后作为参数,您可以传递brokers
。所以官方文档似乎对我有点误导。
from("kafka:{{consumer.topic}}?brokers={{kafka.host}}:{{kafka.port}}"
+ "&maxPollRecords={{consumer.maxPollRecords}}"
+ "&consumersCount={{consumer.consumersCount}}"
+ "&seekTo={{consumer.seekTo}}"
+ "&groupId={{consumer.group}}")
.routeId("FromKafka")
.log("${body}");
但是作为一般建议:Camel是open source,所以你可以随时查看github上的代码和示例。您还可以找到您在那里发布的堆栈跟踪线,然后找出缺少的内容。