如何在独立应用程序中正确阻止camelContext被杀死 [英] How to properly stop camelContext from being killed in a standalone application

查看:29
本文介绍了如何在独立应用程序中正确阻止camelContext被杀死的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了创建一个使用 ActiveMQ 队列的 Camel 应用程序,我按照本教程编写了一个独立的 Camel 应用程序:http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html

区别在于使用了来自camel-spring而不是camel-core的Main类:

我的主要课程:

尝试{Main main = new Main();main.setApplicationContextUri("conf/spring-context.xml");main.run();} 捕捉(异常前){LOGGER.error(String.format(DifClientConstants.ERROR_START_CLIENT, ex.getMessage()), ex);}

文件 spring-context.xml 中的我的骆驼上下文:

<预><代码>...<!-- Camel 上下文配置--><camelContext xmlns="http://camel.apache.org/schema/spring"><routeBuilder ref="myRoutes"/></camelContext>...

我通过支持某些命令的脚本启动此应用程序,例如:启动、停止、重新启动.对于 stop 命令,我终止了应用程序的进程.问题是应用程序与 ActiveMQ 的连接似乎没有关闭:

警告 |传输连接到:tcp://172.16.x.x:58363 失败:java.net.SocketException:连接重置 |org.apache.activemq.broker.TransportConnection.Transport |ActiveMQ 传输:tcp:///172.16.x.x:58363@61616警告 |传输连接到:tcp://172.16.x.x:58325 失败:java.io.EOFException |org.apache.activemq.broker.TransportConnection.Transport |ActiveMQ 传输:tcp:///172.16.x.x:58325@61616

那么问题来了,我如何强制 Camel 应用程序在通过进程终止关闭时关闭其所有连接?

解决方案

按照 Strelok 的评论,我查了一下,发现进程被 kill -9 (SIGKILL) 杀死了.我只使用了 kill 并执行了骆驼优雅关闭,警告也消失了.@Strlok 谢谢

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:

My Main class:

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

My camelContext in file spring-context.xml:

...

    <!-- Camel context configuration -->
    <camelContext xmlns="http://camel.apache.org/schema/spring">
        <routeBuilder ref="myRoutes" />
    </camelContext>
...

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

So the question is, how can I force Camel application to close all its connection when shutdown by process killing?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆