我正在尝试使用Spring Boot 1.5.2.RELEASE + Camel (Spring Boot Starter) + ActiveMQ来实现一个非常简单的路由,即从特定队列中读取并进行日志记录。然而,似乎它没有选择我的spring.activemq配置URL,因为我在日志中看到它正在尝试连接到不同的URL,并且它继续连接它,我的Spring Boot应用程序从未启动。基于我提供的配置,以下是我的问题:
我在控制台上看到的错误,这个错误持续了大约60-70次尝试并继续增加。您可以看到Camel正在选择的代理URL是一些默认URL,可能是Spring默认配置的。
- 修复配置以允许Spring的activemq配置
- 配置maxReconnectAttempts,以便如果ActiveMQ实例关闭,则不会一直尝试连接无法到达的URL
我在控制台上看到的错误,这个错误持续了大约60-70次尝试并继续增加。您可以看到Camel正在选择的代理URL是一些默认URL,可能是Spring默认配置的。
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>
应用程序配置文件 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路由
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");
}
}