gpt4 book ai didi

java - 如何配置apache Camel查看关闭原因?

转载 作者:行者123 更新时间:2023-11-30 07:07:20 25 4
gpt4 key购买 nike

前提条件:

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 正在继续,最后没有任何错误报告,只是关闭。这看起来像:

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

关于java - 如何配置apache Camel查看关闭原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39852745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com