当前位置: 首页 > 面试题库 >

camel ActiveMQ + Spring Boot无法读取Spring ActiveMQ配置

贺景铄
2023-03-14
问题内容

我正在尝试使用Spring Boot 1.5.2.RELEASE + Camel(Spring Boot Starter)+
ActiveMQ进行非常简单的路由,该路由是从特定队列中读取然后进行记录。但是,看起来好像没有在URL中获取我的spring.activemq配置,正如我在日志中看到的那样,它正在尝试连接到另一个url,并且它将继续连接它,而我的spring
boot应用程序永远不会启动。这些问题基于我在下面提供的配置,该如何执行以下操作:

  1. 修复配置以允许spring的activemq配置
  2. 配置maxReconnectAttempts,以便在URL不可访问时不会尝试永久连接,如果ActiveMQ实例关闭,则可能会永久连接

任何帮助将不胜感激。我确实在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中指定的属性创建一个。

之后,您也必须配置骆驼ActiveMQComponent。如果您想重复使用ConnectionFactory(由自动配置创建的),则可以通过以下方式实现:

@Configuration
public class ActiveMQComponentConfig {

    @Bean(name = "activemq")
    public ActiveMQComponent createComponent(ConnectionFactory factory) {
        ActiveMQComponent activeMQComponent = new ActiveMQComponent();
        activeMQComponent.setConnectionFactory(factory);
        return activeMQComponent;
    }
}

您可以在Camel的ActiveMQ文档中找到更多信息。



 类似资料:
  • 我刚开始穿弹力靴。这就是我要解决的问题。我有一个application.yml文件,它具有以下属性: 我尝试使用以下代码访问KinesisSenderFeature的值: 以及 PropertySourcesPlaceHolderConfigureer bean定义为: 是的,我确实看到了: 将Yaml中的列表映射到Spring Boot中的对象列表 Spring boot YAML配置未读取所有

  • 在我的保险库和领事整合我有以下秘密引擎enble 以以下错误结束 待覆盖的Vault-Value其他:待覆盖的Vault-Value已成功连接到数据库 在上下文初始化期间-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建名为“demo application”的bean时出错:调用init方法失败;嵌套异常为java

  • 目前,我在为springboot项目获取mysql数据时遇到了一个问题: 编辑:Application.Properties 我能够使/test/welcome映射工作,因此我相信我对服务和控制器的实现是正确的。所以我想知道我是不是在访问存储库中的数据库时犯了一个错误,还是应该使用JpaRepository而不是CrudRepository并使用显式查询? 编辑堆栈跟踪:org.springfra

  • 带Springdoc的Spring Boot 2.6.3。 在,当我将路径设置为/v3/api docs或将其删除时,这意味着使用默认路径“/v3/api docs”。Swagger UI页面与API一起正确显示http://localhost:8080/swagger-用户界面/索引。html 但我想覆盖下面的路径 然后SwaggerUI显示"加载远程配置失败"错误:

  • 我已经创建了一个SpringBoot应用程序,并且我将Application.properties放置在jar文件的同一个文件夹中。这是文件的内容: 当我在jar文件夹外运行/bin/java-jar/opt/apl/org.web.exemplo-java-maven.1.0.0-90/org.web.exemplo-java-maven-1.0.0-90.jar时,它不读取applicatio

  • 我已经按照下面的链接使用spring的Swagger为我的REST服务创建API文档。 http://jakubstas.com/spring-jersey-swagger-configuration/#comment-1726 一切都很顺利,但当我试图使用url http://localhost:8080/rest/api-docs访问swagger的api文档时,我发现无法读取swagger

  • 本文向大家介绍详解springboot + profile(不同环境读取不同配置),包括了详解springboot + profile(不同环境读取不同配置)的使用技巧和注意事项,需要的朋友参考一下 具体做法: 不同环境的配置设置一个配置文件,例如:dev环境下的配置配置在application-dev.properties中;prod环境下的配置配置在application-prod.prope

  • 问题内容: Cobra和Viper中的文档使我感到困惑。我做了,然后在项目目录中做了。我有一个名为,这里是命令中的init函数。 我的配置文件如下所示: 当我打电话给我的时候 当我打电话时看到了… 因此它正在使用配置文件,但是似乎没有人正在读取它。也许我误解了眼镜蛇和毒蛇的工作方式。有任何想法吗? 问题答案: 要结合和,首先使用Cobra定义标志: 与Viper绑定: 并通过Viper方法获取变量