Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache camel 在camel路由中,代码控件无法进入process()方法内部_Apache Camel_Apache Kafka_Kafka Consumer Api - Fatal编程技术网

Apache camel 在camel路由中,代码控件无法进入process()方法内部

Apache camel 在camel路由中,代码控件无法进入process()方法内部,apache-camel,apache-kafka,kafka-consumer-api,Apache Camel,Apache Kafka,Kafka Consumer Api,我正在尝试使用camel来使用Kafka消息 以下代码: public class Main { private static CamelContext context = new DefaultCamelContext(); public static void main(String[] args) { // TODO Auto-generated method stub try { context.start(); context.ad

我正在尝试使用camel来使用Kafka消息

以下代码:

public class Main {

private static CamelContext context = new DefaultCamelContext();

public static void main(String[] args) {
    // TODO Auto-generated method stub

    try {
        context.start();
        context.addRoutes(new RouteBuilder() {

            @Override
            public void configure() throws Exception {

                System.out.println("Configuring Routes");

                from("kafka:172.16.30.5:9093?topic=reddy&groupId=testing&autoOffsetReset=earliest&consumersCount=1")                
                .process(new Processor(){

                    @Override
                    public void process(Exchange exchange) throws Exception {


                        /*System.out.println("Processing..");
                        System.out.println("Messages:");
                        System.out.println(exchange.getIn());*/

                        String messageKey = "";
                        if (exchange.getIn() != null) {
                            Message message = exchange.getIn();
                            Integer partitionId = (Integer) message
                                    .getHeader(KafkaConstants.PARTITION);
                            String topicName = (String) message
                                    .getHeader(KafkaConstants.TOPIC);
                            if (message.getHeader(KafkaConstants.KEY) != null)
                                messageKey = (String) message
                                        .getHeader(KafkaConstants.KEY);
                            Object data = message.getBody();


                            System.out.println("topicName :: "
                                    + topicName + " partitionId :: "
                                    + partitionId + " messageKey :: "
                                    + messageKey + " message :: "
                                    + data + "\n");
                        }

                        }

                });

            }
        });
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}
输出:

java -jar camelKafka-0.0.1-SNAPSHOT-jar-with-dependencies.jar 
log4j:WARN No appenders could be found for logger     (org.apache.camel.impl.DefaultCamelContext).
log4j:WARN Please initialize the log4j system properly.
Configuring Routes

也就是说,代码控件根本不进入进程方法。

您需要保持Camel运行,请参阅此文档:

当我尝试使用Camel将文件从一个位置传输到另一个位置时,此文档非常有用……但在卡夫卡消息消耗方面没有帮助。不知何故,代码控件仍然没有进入进程()!!知道吗?如果在from()之后但在process()之前添加一个log(),这是在记录吗?