You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3集成ActiveMQ Artemis与Apache Camel:RouteBuilder无法正常工作

Spring Boot 3 + Apache Camel + ActiveMQ Artemis 路由无法运行的排查与修复

核心问题与修复步骤

1. 依赖版本兼容性问题

Spring Boot 3 基于 Jakarta EE 9+,而你使用的 Camel 3.20.2 仍依赖旧的 javax.* 包,会导致类加载冲突。必须升级到适配 Spring Boot 3 的 Camel 4.x 版本,同时精简重复依赖:

修改后的 pom.xml 依赖:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.5</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<!-- 适配Spring Boot3的Camel核心依赖 -->
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>4.0.0</version>
</dependency>
<!-- Artemis专属Camel组件,替代原activemq组件 -->
<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-artemis-starter</artifactId>
    <version>4.0.0</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- spring-boot-starter-artemis已包含artemis-jms-client,无需单独引入 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-artemis</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

2. Camel 组件选型错误

你路由中使用的 activemq 组件是针对 ActiveMQ Classic 的,Artemis 需要用专属的 artemis 组件,否则无法正确连接 Artemis Broker:

修改后的 ArtemisMQRouter 类:

@Component
@Slf4j
public class ArtemisMQRouter extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("artemis:queue:input")
                .routeId("ArtemisMQRouter")
                .log(LoggingLevel.INFO, log, "Message received from artemis:queue:input")
                .to("artemis:queue:output")
                .log(LoggingLevel.INFO, log, "Message successfully sent to the artemis:queue:output");
    }
}

注:移除了重复的 id("activemq:queue:input"),避免节点ID冲突。

3. Artemis 连接模式配置错误

spring.artemis.mode=native 是启动嵌入式 Artemis Broker 的配置,如果你要连接独立部署的 Artemis Broker,必须改为 client 模式:

修改后的 application.properties:

spring.artemis.broker-url=tcp://localhost:61616
camel.springboot.auto-startup=true
spring.artemis.password=admin
spring.artemis.user=admin
# 连接独立Broker时设置为client模式
spring.artemis.mode=client
camel.servlet.mapping.context-path=/services/*

验证步骤

  1. 确保本地 Artemis Broker 已启动,且配置的用户名/密码、端口正确;
  2. 若 Broker 未开启自动创建队列,需手动创建 input 和 output 队列;
  3. 启动 Spring Boot 应用,发送测试消息到 input 队列,查看应用日志是否输出预期的接收/发送日志,同时检查 output 队列是否收到消息。

内容的提问来源于stack exchange,提问作者user3611772

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 12:42:45