我正在尝试使用Spring Boot 1.5.2.RELEASE + Camel(Spring Boot Starter)+ ActiveMQ进行非常简单的路由,该路由是从特定队列中读取然后进行记录。但是,看起来好像没有在URL中获取我的spring.activemq配置,正如我在日志中看到的那样,它正在尝试连接到另一个url,并且它将继续连接它,而我的spring boot应用程序永远不会启动。这些问题基于我在下面提供的配置,该如何执行以下操作:
任何帮助将不胜感激。我确实在stackoverflow上搜索了相关问题,但没有一个给我解决所面临问题的解决方案
我在控制台上看到错误,并且仍然喜欢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"); } }
首先,您应该将spring-boot-starter- activemq依赖项添加到pom.xml中。然后,您可以使用其自动配置功能,该功能将ConnectionFactory根据您在application.yml中指定的属性创建一个。
spring-boot-starter- activemq
ConnectionFactory
之后,您也必须配置骆驼ActiveMQComponent。如果您想重复使用ConnectionFactory(由自动配置创建的),则可以通过以下方式实现:
ActiveMQComponent
@Configuration public class ActiveMQComponentConfig { @Bean(name = "activemq") public ActiveMQComponent createComponent(ConnectionFactory factory) { ActiveMQComponent activeMQComponent = new ActiveMQComponent(); activeMQComponent.setConnectionFactory(factory); return activeMQComponent; } }
您可以在Camel的ActiveMQ文档中找到更多信息。