骆驼ActiveMQ + Spring Boot无法读取Spring ActiveMQ配置 [英] Camel ActiveMQ + Spring boot not reading spring activemq configurations

查看:190
本文介绍了骆驼ActiveMQ + Spring Boot无法读取Spring ActiveMQ配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用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:


  1. 修复该配置以允许spring的activemq配置

  2. 配置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次尝试和计数。如您所见,骆驼拾取的代理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中。然后,您可以使用其自动配置功能,该功能将根据您在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 (由autoconfig创建),则可以通过以下方式实现:

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;
    }
}

您可以在骆驼的ActiveMQ文档

这篇关于骆驼ActiveMQ + Spring Boot无法读取Spring ActiveMQ配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆