我有一个使用spring-boot,Apache Camel和active MQ的应用程序。驼峰路由是activeMQ队列轮询路由。
这是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 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主类
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;
Camel Routes:
/**
* 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();
}
}
答案 0 :(得分:0)
如果您不使用spring-boot-starter-web,则应启用Camel运行控制器选项。
上的选项文档您只需使用普通的Spring启动配置样式进行配置。