我正在尝试使用 Spring Boot 1.5.2.RELEASE + Camel (Spring Boot Starter) + ActiveMQ 的非常简单的路线,即从特定队列读取然后记录它。但是,它看起来好像没有获取我的 spring.activemq URL 配置,正如我在日志中看到的那样,它正在尝试连接到不同的 url,并且它继续连接它,而我的 spring boot 应用程序永远不会启动。这些问题基于我在下面提供的配置,我该如何执行以下操作:
- 修复配置以允许 spring 的 activemq 配置
- 配置 maxReconnectAttempts,以便在 URL 无法访问时不会尝试永远连接(如果 ActiveMQ 实例出现故障,则可能会出现这种情况)
任何帮助将不胜感激。我确实在 stackoverflow 上搜索了相关问题,但没有一个给我解决我面临的问题
我在控制台上看到错误,并且持续尝试 60-70 次并且还在增加。正如你所看到的,camel 获取的代理 URL 是 spring 默认配置的一些默认 URL
Failed to connect to [tcp://localhost:61616] after: 10 attempt(s) continuing to retry.
这是我当前的配置/代码:
pom.xml - 相关部分
<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>
应用程序.yml(Spring Boot ActiveMQ 属性)
spring:
activemq:
brokerUrl: tcp://my.company.host:[port] //This port is up and running
user: user
password: password
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");
}
}