本文介绍了当activemq连接丢失时,Spring Context关闭骆驼路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用 spring-boot、Apache Camel 和 active MQ 的应用程序.骆驼路由是 activeMQ 队列轮询路由.
I have an application using spring-boot, Apache Camel and active MQ. The camel routes are activeMQ queue polling routes.
这是骆驼上下文.xml
This is the camel-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:amq="http://activemq.apache.org/schema/core"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>file:${envpath}/activemqApplication.properties</value>
</list>
</property>
</bean>
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="maximumActiveSessionPerConnection" value="${message.sessions.per.connection}"/>
<property name="maxConnections" value="${message.max.connections}"/>
</bean>
<bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" primary="true">
<property name="brokerURL" value="${message.broker.url}"/>
<property name="trustAllPackages" value="true"/>
</bean>
<bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
</bean>
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="connectionFactory" ref="pooledConnectionFactory"/>
<property name="transactionManager" ref="jmsTransactionManager"/>
<property name="usePooledConnection" value="true"/>
<property name="concurrentConsumers" value="${activemq.concurrency}" />
</bean>
<bean id="fileSupport" class=" com.archive.app.module.helper.filesSupport">
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring">
<package>com.fileSupport.app.routes</package>
</camelContext>
</beans>
这些是课程
Spring Boot 类
Spring boot class
package com.fileSupport.app;
import org.springframework.boot.SpringApplication;
public final class FileSupportMain {
public static void main(final String[] args) {
SpringApplication app = new SpringApplication(FileArchiveSpringBootApplication.class);
app.setWebEnvironment(false);
app.run(args);
}
private FileSupportMain() {
}
}
Spring Boot 主类
Spring boot main class
package com.fileSupport.app;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@ImportResource({"classpath:/META-INF/spring/camel-context.xml"})
@EnableConfigurationProperties
@SpringBootApplication
public class FileSupportSpringBootApplication {
}
package com.fileSupport.app.routes;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.springframework.stereotype.Component;
骆驼路线:
/**
* ActiveMQ queue is watched by
* this route which then performs content based
* routing on the messages using XPath.
*/
@Component
public final class ConsumeActiveMQmessages extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:queue:" + Variables.RECEIVE_QUEUE1)
.routeId("queueRoute")
.log(LoggingLevel.INFO, "Body: $simple{body}")
.to("activemq:queue:" + Variables.RECEIVE_QUEUE2);
from("activemq:queue:" + Variables.RECEIVE_QUEUE2)
.to("direct:callback");
from("direct:callback")
.log(LoggingLevel.INFO, "body: $simple{body}")
.end();
}
}
推荐答案
如果你没有使用 spring-boot-starter-web 你应该打开 Camel 运行控制器选项.
If you are not using spring-boot-starter-web you should turn on the Camel run controller option.
您只需使用普通的 Spring Boot 配置样式进行配置即可.
You just configure this using normal spring boot configuration style.
这篇关于当activemq连接丢失时,Spring Context关闭骆驼路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!