无法使用Apache Camel使用Kafka消息

时间:2018-06-04 12:09:36

标签: java apache-kafka apache-camel

我无法使用Apache camel消耗在本地模式下运行的Kafka消息。应用程序启动时,我没有查看任何Kafka使用者属性。以下是我的Kafka消费者代码

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class MessageConsumerClient {

    private static final Logger LOG = LoggerFactory.getLogger(MessageConsumerClient.class);

    private MessageConsumerClient() {
    }

    public static void main(String[] args) throws Exception {

        LOG.info("About to run Kafka-camel integration...");

        CamelContext camelContext = new DefaultCamelContext();

        // Add route to send messages to Kafka

        camelContext.addRoutes(new RouteBuilder() {
            public void configure() {
                PropertiesComponent pc = getContext().getComponent("properties", PropertiesComponent.class);
                pc.setLocation("classpath:application.properties");

                log.info("About to start route: Kafka Server -> Log ");

                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}");
            }
        });
        camelContext.start();

        Thread.sleep(5 * 60 * 1000);

        camelContext.stop();
    }

}

我在pom.xml中使用以下依赖项:

1.Camel core - 2.21.1 2.Camel Kafka - 2.21.1

的pom.xml

<dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-core</artifactId>
            <version>2.21.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-kafka</artifactId>
            <version>2.21.1</version>
        </dependency>
    </dependencies>

由于我在执行时无法查看任何日志,所以非常感谢任何帮助。

0 个答案:

没有答案