Camel ActiveMQ + Spring boot不读取spring activemq配置

2023-11-21

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

  1. 修复配置以允许 spring 的 activemq 配置
  2. 配置 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");
    }

}

首先你应该添加spring-boot-starter-activemq依赖于您的 pom.xml。然后您可以使用其自动配置功能,这将创建一个ConnectionFactory基于您在 application.yml 中指定的属性。

之后你必须配置Camel的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文档.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Camel ActiveMQ + Spring boot不读取spring activemq配置 的相关文章

随机推荐

  • PHP,strip_tags 在文本区域中剥离 \n。怎么阻止呢?

    我希望能够接受 n or r n并将它们转换为 br 以在页面中使用 尽管当用户提交包含新段落的文本区域时 strip tags函数似乎将它们直接剥离了 我能做些什么来将这些保留在字符串中吗 谢谢 您可以使用nl2br添加BR换行符元素到换
  • 如何编写写入 stdin 的 Go 测试?

    假设我有一个简单的应用程序 它从标准输入读取行并简单地将其回显到标准输出 例如 package main import bufio fmt io os func main reader bufio NewReader os Stdin fo
  • Hibernate @OrderBy 与引用的类

    我有一堂课说 ClassA 其中有 ClassB 的集合 OneToMany cascade CascadeType ALL fetch FetchType LAZY JoinColumn name COLUMN NAME private
  • 如何从 C++ 对象中获取类名?

    是否也可以获取对象名称 include
  • 如何在 AOSP 构建中添加 APK?

    我需要将一些第 3 方 APK 添加到我的 AOSP 版本中 我应该将这些 APK 保存在哪个文件夹中 以便在构建代码并创建映像时将其安装在模拟器中 看起来系统应用程序保存在包 应用程序文件夹 所以我需要知道第三方 APK 的保存位置 将第
  • 使用具有特定精度的小数作为 Dapper 的输出参数

    我正在评估 Dapper 作为自定义和繁琐代码的替代品 到目前为止 一切都非常好并且很有前途 但是今天早上我偶然发现了动态参数的问题并且找不到解决方案 存储过程计算客户的帐户余额和可用余额 并以两位小数输出参数返回其结果 这些小数在存储过程
  • 使用 Java8 计算 int 出现次数

    Java8 有没有更好的方法来计算 int 出现次数 int monthCounter new int 12 persons stream forEach person gt monthCounter person getBirthday
  • 两个 Wifi 设备之间的数据传输

    我在谷歌上搜索过 在 Android 2 2 和 sdk 8 中 如何在 Android 列表中使用 SSID 通过使用 SSID 应以编程方式获取特定的启用 WiFi 的设备属性 有了这个帮助 应该可以在 Android 中的两个支持 W
  • 如何在postgres中编写组合函数?

    我有一个这种形式的 PostgreSQL 表 base id int mods smallint 3 7 15 48 我需要填充这种形式的表 combo id int base id int mods smallint 1 3 2 3 7
  • pprint 对字典排序但不对集合排序?

    我知道字典和集合没有排序 因此相等的集合或字典可能会以不同的方式打印 所有测试都使用Python 3 6 1 gt gt gt for obj in 0 8 8 0 0 0 8 8 8 8 0 0 print obj 0 8 8 0 0 0
  • Jaxer 的优点和缺点

    我意识到这个问题已经之前问过 但已经一个月了 没有像样的回应 我正在看阿普塔纳的贾克瑟我发现这个概念非常令人兴奋 对于那些不熟悉的人来说 这里是一个快速概述 用他们的话来说 Jaxer 是 世界上第一个真正的 AJAX 服务器 它基于 Mo
  • geom_bar(position = "dodge") 中的条形宽度相同

    我想绘制具有相同宽度的条形图 这是我的最小示例代码 data lt data frame A letters 1 17 B sample 1 500 17 C c rep 1 5 rep 2 6 rep c 3 4 5 each 2 ggp
  • Android 应用程序在卸载并重新安装后会记住其数据

    在开发针对 4 1 以上所有版本的 Android 应用程序时 我发现卸载应用程序并再次安装不会清除其数据 该应用程序旨在存储其在第一个屏幕中询问的详细信息 在操作系统版本4 4 4中卸载并重新安装后 应用程序会提示用户填写数据 这是正常现
  • 地点自动完成状态代码 9001

    我试图使用 Google Play 服务中的 Places Autocomplete API 进行地点预测 但这是我得到的状态 Status statusCode unknown status code 9001 resolution nu
  • Apache Flink:如何为动态表启用“upsert 模式”?

    我看到好几处提到 更新插入模式 Flink 文档和 Flink 官方博客中基于唯一键的动态表 但是 我没有看到任何有关如何在动态表上启用此模式的示例 文档 例子 博客文章 当通过更新模式在流上定义动态表时 我们可以指定一个唯一键表上的属性
  • 转换说明符 %ju

    在下一页中 我找到了类似的代码 CERT INT15 C 使用 intmax t 或 uintmax t 对程序员定义的整数类型进行格式化 IO uintmax t temp if scanf ju temp 1 我不熟悉 ju 说明符 而
  • 如何删除 ActionBar 上应用程序图标和屏幕边缘之间的边距?

    我的应用程序有一个自定义主页图标 我希望它一直与操作栏的左侧对齐 以便它接触屏幕边缘 这可能吗 如果可以 该怎么做 我没有看到任何设置填充或边距以使其一直向左对齐的内容 我终于得到了这个 您需要使用自定义操作栏视图 其实很简单 这是使用 A
  • 使用枚举基编写枚举时出现不明确的重载,但仅使用 clang

    我想使用运算符 include
  • 如何在可绘制形状 XML 选择器中制作底部边框?

    我正在尝试为我的按钮创建一个具有不同状态的可绘制形状 所以我写了这个
  • Camel ActiveMQ + Spring boot不读取spring activemq配置

    我正在尝试使用 Spring Boot 1 5 2 RELEASE Camel Spring Boot Starter ActiveMQ 的非常简单的路线 即从特定队列读取然后记录它 但是 它看起来好像没有获取我的 spring activ