gpt4 book ai didi

java - 当 activemq 连接丢失时,Spring Context 关闭 Camel 路由

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:44 25 4
gpt4 key购买 nike

我有一个使用 spring-boot、Apache Camel 和 active MQ 的应用程序。 Camel 路由是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启动类

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 路线:

/**
* 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 运行 Controller 选项。

请参阅该选项的文档:https://github.com/apache/camel/blob/master/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java#L124

您只需使用正常的 Spring Boot 配置样式进行配置即可。

关于java - 当 activemq 连接丢失时,Spring Context 关闭 Camel 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41755670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com