如何正确阻止camelContext在独立应用程序中被杀死 [英] How to properly stop camelContext from being killed in a standalone application
问题描述
要创建一个从ActiveMQ队列中使用的Camel应用程序,我按照本教程编写了一个独立的Camel应用程序:
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
To create a Camel application which consumes from ActiveMQ's queue, I wrote a standalone Camel application following this tutorial: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
区别在于使用的是骆驼弹簧的主要类别,而不是骆驼核心:
The difference was The Main class from camel-spring used instead of camel-core:
我的主类:
try {
Main main = new Main();
main.setApplicationContextUri("conf/spring-context.xml");
main.run();
} catch (Exception ex) {
LOGGER.error(String.format(DifClientConstants.ERROR_START_CLIENT, ex.getMessage()), ex);
}
我的camelContext在spring-context.xml文件中:
...
<!-- Camel context configuration -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="myRoutes" />
</camelContext>
...
我通过支持某些命令的脚本启动此应用程序,例如:启动,停止,重新启动。
对于停止命令,我将终止应用程序的进程。
问题是应用程序与ActiveMQ的连接似乎未关闭:
I start this application by a script which supports some commands such as: start, stop, restart. For the stop command, I kill application's process. Problem is application's connection to ActiveMQ seems not to be closed:
WARN | Transport Connection to: tcp://172.16.x.x:58363 failed: java.net.SocketException: Connection reset | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///172.16.x.x:58363@61616
WARN | Transport Connection to: tcp://172.16.x.x:58325 failed: java.io.EOFException | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///172.16.x.x:58325@61616
所以问题是,如何
推荐答案
在Strelok的评论之后,我检查并发现,我可以强制Camel应用程序在通过进程终止关闭时关闭其所有连接吗?该过程被 kill -9(SIGKILL)
杀死。我只使用了 kill
,然后执行了骆驼般的正常关机,警告也消失了。
@Strlok谢谢
Following Strelok's comment, I checked and found that the process was killed by kill -9 (SIGKILL)
. I used only kill
and the camel graceful shutdown executed, also the WARN gone.
@Strlok Thank you
这篇关于如何正确阻止camelContext在独立应用程序中被杀死的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!