我用的是带camel和ActiveMQ的spring-boot。
我通过@EnableJms注释使用ActiveMQComponent自动配置。但创建我自己的ActiveMQComponent以在所有队列上启用“事务处理(真)”。
@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
然后后来:
< code > 2017-05-04 18:21:59.766 INFO 12188-[-shutdownstask]o . a . camel . impl . defaultshutdownstrategy:正在等待,因为仍有1个正在进行的和待定的交换要完成,300秒后超时。每条路线的影响:[test2 = 1]
谁能帮我配置Spring启动骆驼活动所有一起优雅的关闭?
谢谢。
更新:这里是我的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:经过进一步的调查和创建一个新项目,逐个添加每个修改,我已经隔离了问题。
关闭工作正常,直到我添加特定endpoint:
@EndpointInject(uri = "direct:aaa")
private Endpoint errorHandling;
使用:
private String errorHandling = "direct:aaa";
不会产生错误。
似乎使用@Endpoint Inject会先关闭Active emq
更新 3 :
发现 SpringCamelContext 没有实现 ApplicationListener,因此它的方法 “onApplicationEvent” 它不称为处理 camel的 “shutdownEager”。
我在使用Spring Boot、ActiveMQ或A-MQ和Camel(版本2.18.1.redhat-000012)运行单元/集成测试时也遇到了同样的问题。显然,当Spring Boot关闭时,JMS线程池会在Camel上下文关闭之前关闭,这是错误的顺序。@John D在Camel用户邮件列表线程中提供了与他在该线程中提供的类似的代码修复。以下是适用于我的John D代码版本:
@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);
}
}
显然,自 https://issues.apache.org/jira/browse/CAMEL-2607 以来,SpringCamelContext不再实现ApplicationListener接口。
由于我使用的是 spring-boot 自动配置,所以我没有使用添加侦听器的 CamelContextFactoryBean。
我创建了一个组件来监听ApplicationEvent并将它们分派给SpringCamelContext方法:
public class SpringCamelContextFix implements ApplicationListener<ApplicationEvent> {
private SpringCamelContext camelContext;
public SpringCamelContextFix(SpringCamelContext camelContext) {
this.camelContext = camelContext;
}
@Override
public void onApplicationEvent(ApplicationEvent event) {
camelContext.onApplicationEvent(event);
}
}
重要的是要使用骆驼Spring启动机。
http://camel.apache.org/spring-boot.html
如何在我的Spring Boot应用程序中启用Camel自动配置?
只需将骆驼Spring靴罐放入您的类路径中:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version> <!-- use the same version as your Camel core version -->
</dependency>
骆驼Spring靴罐随Spring而来。工厂文件,所以一旦您将该依赖项添加到类路径中,Spring Boot将自动为您配置Camel。耶!这很快;)。
自动配置的Camel上下文
Camel自动配置提供的最重要的功能是CamelContext实例。
Camel自动配置为您创建SpringCamelContext,并处理该上下文的正确初始化和关闭。
创建的Camel上下文也在Spring应用程序上下文中注册(在camelContext bean名称下),因此您可以像访问任何其他Spring bean一样访问它。
@Configuration
public class MyAppConfig {
@Autowired
CamelContext camelContext;
@Bean
MyService myService() {
return new DefaultMyService(camelContext);
}
}
要求是为httpendpoint设置connectionTimeout。我使用的是http4组件和http协议。httpClient。connectTimeout适用于https,不适用于http。 并尝试设置连接TimeToLive=1参数也在http 4组件bean和它是不工作。 我发现socketTimeout参数正在工作。但要求是设置connectionTimeout。 请建议是否有任何方
我有哪些选项可以将Kafka与Spring靴骆驼连接? 我正在运行ActiveMQ Artemis和Camel,以建立进出客户端的JMS/MQTT和REST路由。我想把Kafka添加到这个二重唱中,以流式传输/交换数据(视频音频、文件/文本)。 到目前为止,我下载了Kafka汇合平台(免费试用),我正在测试他们提供什么。在融合平台中,我看到有可能将连接器作为“插件”添加。我假设我可以添加Camel
我正在骆驼中开发一种机制,它将从一个可以是真或假的标志中为消息选择一个endpoint。这是一种节流机制,在我的上游通道被洪水淹没的情况下,它将把消息重新路由到批量摄取endpoint(发送到HDFS)。 最终,我的路线是这样的: 我的ThrottleHelper类的buildEndpoint方法如下所示: 目前,我在类上有一个名为checkStatus()的方法;设置shouldThrottle
背景:我按照这个链接设置了AWS MSK,并测试了生产者和消费者,它的设置和工作正常。我能够通过两个单独的EC2实例发送和接收消息,这两个实例都使用同一个Kafka集群(我的MSK集群)。现在,我想建立一条从Eventhubs到AWS Firehose的数据管道,其形式如下: Azure Eventhub- 我能够成功地做到这一点,没有使用MSK(通过常规的老Kafka),但由于未说明的原因,需要
我已经尝试了几个小时来获取Spring Boot应用程序的Camel路由(通过Camel组件camel-google-pubsub连接到Google Pubsub模拟器的本地实例),但没有成功。 null null 如果有人已经成功地使用pubsub模拟器与他们的骆驼路线,我对您的解决方案感兴趣。
问题可能也与我对这个概念的理解有关。 正在调用代理bean,它是。代理bean接口是使用类实现的。所以我期待返回的通过传递,然后在控制台上流式传输。 Application Context 会计界面 会计Util 动作课 但是我有例外: 还有一个问题,我可以为单个提供多个 我希望使用不同的方法调用不同的,但只是单个接口的一部分。