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

How to configure apache camel to see the reason of the shutdown?

先决条件:

骆驼 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();

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

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

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

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

除此之外,您还可以让自动启动停止并在以后需要时启动 camel 上下文

<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();