我正在使用spring-boot與camel和ActiveMQ。ConnectionFactory在駝峯前被破壞
我通過@EnableJms註釋使用activemq autoconfiguration。 但創建我自己的ActiveMQComponent在所有隊列上啓用「事務處理(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啓動駱駝的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)。它似乎工作 –