【发布时间】:2017-10-02 22:47:58
【问题描述】:
我正在使用带有骆驼和 ActiveMQ 的 spring-boot。
我正在通过@EnableJms 注释使用activemq 自动配置。 但是创建我自己的 ActiveMQComponent 以在所有队列上启用“transacted(true)”。
@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 在骆驼正常关闭发生之前被销毁。
导致大量错误,导致路线无法正确停止。
像这个错误的 20 倍:
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 : Waiting as there are still 1 inflight and pending exchanges to complete, timeout in 300 seconds. Inflights per route: [test2 = 1]
谁能帮我配置spring-boot camel activemq和优雅关机?
谢谢
更新: 这是我的 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: 经过进一步调查并创建了一个新项目,并一一添加了每个修改,我已经隔离了问题。
在我添加特定端点之前,关闭工作正常:
@EndpointInject(uri = "direct:aaa")
private Endpoint errorHandling;
使用:
private String errorHandling = "direct:aaa";
不会产生错误。
似乎使用@EndpointInject 是先关闭activemq
更新 3:
发现 SpringCamelContext 没有实现 ApplicationListener,因此它的方法“onApplicationEvent”没有被称为处理骆驼的“shutdownEager”。
【问题讨论】:
-
方法 SpringCamelContext.onApplicationEvent 使用 ContextStoppedEvent 调用,将日志转为跟踪或调试
-
添加断点,它从未调用过。创建了一个监听这个事件的组件,然后手动调用 springCamelContext.onApplicationEvent(event)。它似乎工作
标签: spring-boot apache-camel activemq