问题描述
我正在尝试使用 Spring Boot 1.5.2.RELEASE + Camel (Spring Boot Starter) + ActiveMQ 的一个非常简单的路线,即从特定队列中读取然后记录它.但是,它似乎没有为 URL 获取 spring.activemq 配置,正如我在日志中看到的那样,它正在尝试连接到不同的 URL,并且它继续连接它,而我的 Spring Boot 应用程序从未启动.这些问题基于我在下面提供的配置,我该如何执行以下操作:
I am trying a very simple route with Spring Boot 1.5.2.RELEASE + Camel (Spring Boot Starter) + ActiveMQ, which is to read from a particular queue and then log it. However, it looks like it is not picking up my spring.activemq configuration for URL as I see in the log it is trying to connect to a different url and it continues to connect it and the my spring boot app never starts. The questions are based on my configuration that I am providing below how can I do the below:
- 修复配置以允许spring的activemq配置
- 配置 maxReconnectAttempts 以便在 URL 不可访问时它不会尝试永远连接,如果 ActiveMQ 实例出现故障,这可能是可能的
任何帮助将不胜感激.我确实在 stackoverflow 上搜索了相关问题,但没有人给我解决我面临的问题
Any assistance would be greatly appreciated. I did search relevant questions on stackoverflow but none gave me a solution to the issue I am facing
我在控制台上看到的错误,这继续像 60-70 次尝试和计数.如您所见,camel 获取的代理 URL 是一些默认 URL,可能是 spring 默认配置的
Error I am seeing on the console and this continues to like 60-70 attempts and counting. As you can see the broker URL that camel is picking up is some default URL that probably spring has configured by default
Failed to connect to [tcp://localhost:61616] after: 10 attempt(s) continuing to retry.
这是我当前的配置/代码:
Here are my current configurations / code:
pom.xml - 相关部分
pom.xml - relevant portion
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<!-- Spring Cloud is part of the project where I am configuring camel routes -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>2.19.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- I have this as the same project works as a web app as well
and therefore I do not need the
camel.springboot.main-run-controller=true configuration to be set
which is as per camel's spring boot documentation-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Camel - start -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-camel</artifactId>
</dependency>
<!-- Camel - end -->
</dependencies>
application.yml (Spring Boot ActiveMQProperties)
application.yml (Spring Boot ActiveMQProperties)
spring:
activemq:
brokerUrl: tcp://my.company.host:[port] //This port is up and running
user: user
password: password
Java 中的骆驼路线
Camel Route in JAVA
package com.mycamel.route;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class SampleAmqCamelRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("activemq:some.queue").to("log:com.mycamel.route?level=INFO&groupSize=10");
}
}
推荐答案
首先,您应该将 spring-boot-starter-activemq
依赖项添加到您的 pom.xml.然后你可以使用它的 AutoConfiguration 功能,它会根据你在 application.yml 中指定的属性创建一个 ConnectionFactory
.
First you should add the spring-boot-starter-activemq
dependency to your pom.xml. Then you can use its AutoConfiguration capabilities which will create a ConnectionFactory
based on the properties you have specified in your application.yml.
之后,您还必须配置 Camel 的 ActiveMQComponent
.如果您想重用 ConnectionFactory
(由自动配置创建),则可以通过以下方式实现:
After that you have to configure Camel's ActiveMQComponent
too. If you would like to reuse the ConnectionFactory
(which created by the autoconfig) then it can be achievable with the following:
@Configuration
public class ActiveMQComponentConfig {
@Bean(name = "activemq")
public ActiveMQComponent createComponent(ConnectionFactory factory) {
ActiveMQComponent activeMQComponent = new ActiveMQComponent();
activeMQComponent.setConnectionFactory(factory);
return activeMQComponent;
}
}
您可以在 Camel 的 ActiveMQ 文档中找到更多信息.
You can find more information in Camel's ActiveMQ documentation.
这篇关于Camel ActiveMQ + Spring boot 不读取 spring activemq 配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!