【问题标题】:How to configure apache camel to see the reason of the shutdown?如何配置apache camel查看关机原因?
【发布时间】:2017-02-12 15:30:07
【问题描述】:

前提条件:

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

【问题讨论】:

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


    【解决方案1】:

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

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

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

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

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

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

    【讨论】:

    • 我拥有的更多更少。问题在于骆驼的冗长。它正在吃异常或其他错误报告,甚至没有将其写入日志。有时在某些 TRACE 级别的日志中我会看到,例如参数为空左右。然后在其他日志行中,我看到“关闭”或“停止”或其他任何内容 - 通常完全不清楚。我希望至少在 WARN 级别看到具体消息,例如“预期类型/值是 String 得到 int。Camel 将关闭”。通过这样的报告,我可以看到原因和结果之间的联系。
    • 在文件中创建带有调试模式的 log4j.xml。你会得到那里的每一步
    • @Aschish:我做到了,它没有太大帮助。我还添加了路由生成器:onException( java.lang.Exception.class ).handled( false ).to( "log:GeneralError?level=ERROR" );,但它也没有多大帮助。也许我错了,但我对 Kafka Camel 插件的代码进行了代码审查,我发现它几乎没有异常处理。也许问题被发送到更高的级别。
    • 请分享您的完整路线。我之前遇到了同样的问题,因为我使用 Spring 我使用了 &lt;bean id="camelTracer" class="org.apache.camel.processor.interceptor.Tracer"&gt; &lt;property name="traceExceptions" value="false"/&gt; &lt;property name="traceInterceptors" value="true"/&gt; &lt;property name="logLevel" value="ERROR"/&gt; &lt;property name="logName" value="com.mycompany.messages"/&gt; &lt;/bean&gt; 并且它记录了一切
    • 我已经扩展了问题的内容。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多