如何配置apache camel看看关机的原因?

时间:2016-10-04 12:46:18

标签: java configuration apache-camel startup error-reporting

先决条件:

Camel 2.17

我定义了一些路由,路由包含如下条目:

.to ("log:org.apache.camel?level=DEBUG")

我的logback配置包含:

<logger name="org.apache.camel" level="TRACE" />

上下文定义以:

开头
<camel:camelContext id="someContext" ... trace="true">

当我启动Camel时,我看到Camel正在继续,最后没有 ANY 错误报告只是关闭。这看起来像:

2016-10-04 13:40:56,146 [localhost-startStop-1] TRACE org.apache.camel.model.ProcessorDefinitionHelper - There are 6 properties on: From[direct:process]
2016-10-04 13:40:58,042 [localhost-startStop-1] DEBUG org.apache.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=Root WebApplicationContext: startup date [Tue Oct 04 13:37:25 CEST 2016]; root of context hierarchy]
2016-10-04 13:40:58,066 [localhost-startStop-1] INFO  org.apache.camel.spring.SpringCamelContext - Apache Camel 2.17.3 (CamelContext: someContext) is shutting down

我也有:

    onException( java.lang.Exception.class )
            .handled( false )
            .to( "log:GeneralError?level=ERROR" );

但这与交换处理有关,而与启动无关。

有没有通用的方法来检查那里发生了什么? 例如:

  • 是否缺少任何类,类加载器失败?
  • 或者抛出任何异常?
  • 或某些连接失败?

完整路线定义:

final RouteDefinition kafkaRouteDefinition = from( "kafka:{{kafka.broker.endpoints}}" +
        "?topic={{kafka.topic.name}}" +
        "&groupId=my_group" +
        "&autoOffsetReset=earliest" +
        "&consumersCount={{kafka.consumer.count}}" );

LOG.info( "Kafka route definition: " + kafkaRouteDefinition.toString() );

kafkaRouteDefinition
        .routeId( Constants.ROUTE_ID_PROCESS_KAFKA_MESSAGES )
        .to( "log:org.apache.camel?level=DEBUG" )
        .process( new RawMessageProcessor() ).id( RawMessageProcessor.class.getSimpleName() )
        .to( "log:org.apache.camel?level=DEBUG" )
        .unmarshal( inputMessageFormat ).id( "ConvertRawMessageToLogline" )
        .to( "log:org.apache.camel?level=DEBUG" )
        .process( new LoglineMessageProcessor() ).id( LoglineMessageProcessor.class.getSimpleName() )
        .to( "log:org.apache.camel?level=DEBUG" )
        .to( Constants.CAMEL_PROCESS_ENDPOINT )
        .to( "log:org.apache.camel?level=DEBUG" )
        .multicast().stopOnException()
        .to( "log:org.apache.camel?level=DEBUG" )
        .to( Constants.CAMEL_STORE_ENDPOINT
                , Constants.CAMEL_INDEX_ENDPOINT
        )
        .to( "log:org.apache.camel?level=DEBUG" )
        .end();

1 个答案:

答案 0 :(得分:1)

我有类似的问题[但我使用的是Spring]

当加载camel Context的main方法在camel context完全加载之前退出时会发生这种情况

在您的测试用例中添加以下代码&amp;它应该运行

org.apache.camel.spring.Main main = new Main();
main.setApplicationContextUri("camel-context.xml");
main.start();
Thread.sleep(1000);

更多关于你也可以使自动启动停止&amp;稍后在需要时启动驼峰上下文

<camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
    <route>
        <from uri="direct:start"/>
        <to uri="mock:result"/>
    </route>
</camelContext>

然后在一些java文件中

ApplicationContext ac = ...
SpringCamelContext camel = (SpringCamelContext) ac.getBean("myCamel");

// now start Camel manually
camel.start();