ConnectionFactory在骆驼之前被销毁 [英] ConnectionFactory get destroyed before camel

查看:92
本文介绍了ConnectionFactory在骆驼之前被销毁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有骆驼和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倍:

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] oacamel.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屋!

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