ConnectionFactory 在骆驼之前被摧毁 [英] ConnectionFactory get destroyed before camel
问题描述
我正在使用带有骆驼和 ActiveMQ 的 spring-boot.
I'm using spring-boot with camel and ActiveMQ.
我正在通过 @EnableJms 注释使用 activemq 自动配置.但是创建我自己的 ActiveMQComponent 以在所有队列上启用transacted(true)".
I'm using activemq autoconfiguration via @EnableJms annotation. But creating my own ActiveMQComponent to enable "transacted(true)" on all queues.
@Bean(name = "activemq")
@ConditionalOnClass(ActiveMQComponent.class)
public ActiveMQComponent activeMQComponent(ConnectionFactory connectionFactory) {
ActiveMQComponent activeMQComponent = new ActiveMQComponent();
activeMQComponent.setConnectionFactory(connectionFactory);
activeMQComponent.setTransacted(true);
activeMQComponent.setTransactionManager(jmsTransactionManager(connectionFactory));
return activeMQComponent;
}
它运行良好,但是当我尝试正常关闭应用程序时.PooledConnectionFactory 在骆驼正常关闭发生之前被销毁.
It works well but when I try to gracefully shutdown the application. The PooledConnectionFactory get destroyed before the camel graceful shutdown happens.
导致大量错误,路线无法正确停靠.
Leading to a tons of error and the route unable to correctly stops.
像这个错误的 20 次:
Like 20 times this error :
2017-05-04 18:21:59.748 WARN 12188 --- [er[test.queue]] o.a.activemq.jms.pool.PooledSession : Caught exception trying rollback() when putting session back into the pool, will invalidate. javax.jms.IllegalStateException: The Session is closed
关注:
2017-05-04 18:21:59.748 INFO 12188 --- [ Thread-18] o.a.camel.spring.SpringCamelContext : Apache Camel 2.18.3 (CamelContext: route) is shutting down
然后:
2017-05-04 18:21:59.766 INFO 12188 --- [ - ShutdownTask] o.a.camel.impl.DefaultShutdownStrategy :等待,因为仍有 1 个飞行中和待处理的交换要完成,300 秒后超时.每条航线的飞行次数:[test2 = 1]
任何人都可以帮我配置 spring-boot camel activemq 以及优雅关机吗?
Anyone can help me configuring spring-boot camel activemq all together with graceful shutdown ?
谢谢
更新:这是我的 pom.xml 示例:
Update : Here is a sample of my pom.xml:
<properties>
<!-- Spring -->
<spring-boot.version>1.4.3.RELEASE</spring-boot.version>
<!-- Camel -->
<camel-spring-boot.version>2.18.3</camel-spring-boot.version>
</properties>
....
<!-- Camel BOM -->
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel-spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
...
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<!-- ActiveMQ -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-pool</artifactId>
</dependency>
<!-- Camel -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
更新 2:经过进一步调查和创建一个新项目,将每一个修改都一一添加,我已经隔离了问题.
Update 2: After further investigation and the creation of a new project adding every modification one by one I have isolated the problem.
关闭工作正常,直到我添加一个特定的端点:
The shutdown works correcly until I add a specific endpoint :
@EndpointInject(uri = "direct:aaa")
private Endpoint errorHandling;
使用:
private String errorHandling = "direct:aaa";
不会产生错误.
似乎使用@EndpointInject 使 activemq 首先关闭
It seems like using @EndpointInject is making the activemq close first
更新 3:
发现 SpringCamelContext 没有实现 ApplicationListener,因此它的方法onApplicationEvent"没有被调用来处理骆驼的shutdownEager".
Found that SpringCamelContext is not implementing ApplicationListener and thus its method "onApplicationEvent" its not called handling the "shutdownEager" of camel.
推荐答案
我在使用 Spring Boot、ActiveMQ 或 A-MQ 和 Camel(版本 2.18.1.redhat-000012)运行单元/集成测试时遇到了同样的问题.显然,当 Spring Boot 关闭时,JMS 线程池在 Camel 上下文关闭之前关闭,这是错误的顺序.@John D 在 Camel 中提供了代码修复用户邮件列表线程 类似于他在此线程中提供的内容.以下是适用于我的 John D 代码版本:
I had this same problem running unit/integration tests with Spring Boot, ActiveMQ or A-MQ, and Camel (version 2.18.1.redhat-000012). Apparently, when Spring Boot shuts down, the JMS thread pool is closed before the Camel context is shutdown, which is the wrong order. @John D provided a code fix in a Camel users mailing list thread which is similar to what he provided in this thread. Here is the version of John D's code that worked for me:
@Component
public class SpringCamelContextFix implements
ApplicationListener<ApplicationEvent> {
@Inject
private SpringCamelContext camelContext;
public SpringCamelContextFix(SpringCamelContext camelContext) {
this.camelContext = camelContext;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
camelContext.onApplicationEvent(event);
}
}
这篇关于ConnectionFactory 在骆驼之前被摧毁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!