【发布时间】:2017-06-24 16:52:28
【问题描述】:
为了创建一个使用 ActiveMQ 队列的 Camel 应用程序,我按照本教程编写了一个独立的 Camel 应用程序: http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
不同之处在于使用了camel-spring的Main类而不是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);
}
我在 spring-context.xml 文件中的 camelContext:
...
<!-- Camel context configuration -->
<camelContext xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="myRoutes" />
</camelContext>
...
我通过一个脚本启动这个应用程序,该脚本支持一些命令,例如:启动、停止、重新启动。 对于 stop 命令,我会终止应用程序的进程。 问题是应用程序与 ActiveMQ 的连接似乎没有关闭:
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
所以问题是,如何强制 Camel 应用程序在通过进程终止关闭时关闭其所有连接?
【问题讨论】:
-
如果应用程序正在主动读取/写入队列,您将无法关闭连接
-
你是如何杀死进程的?在后一种情况下,标准 kill (SIGTERM) 或 kill -9 (SIGKILL) 将不会执行 Camel 关闭挂钩,并且 Camel 不会执行 graceful shutdown。
-
将 JMS 连接池配置为在 JVM 停止时关闭/销毁。在这里查看销毁:camel.apache.org/activemq
标签: java spring apache-camel activemq