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

Docker部署Spring Boot集成ActiveMQ Artemis外部无法连接求解决方案

问题原因

你遇到的问题核心是Artemis服务仅绑定了Docker容器内部的环回地址,无法接收外部请求:

  • 你在ArtemisConfigurationCustomizer配置中,将Acceptor地址写死为tcp://localhost:61616,对应的是容器内的127.0.0.1环回接口,只有容器内部运行的进程可以访问该地址
  • Docker的端口映射-p 61616:61616是将宿主机的请求转发到容器的对外网卡(一般为eth0),请求根本无法抵达绑定在环回接口的Artemis服务,因此会触发连接超时错误
  • 你提到的OpenWire协议配置也出现相同问题,本质原因也是Acceptor绑定了localhost地址
解决方案

修改SpringBootExampleConfiguration配置类中的Acceptor绑定地址即可:

@Configuration
@EnableJms
public class SpringBootExampleConfiguration {
    @Bean
    public ArtemisConfigurationCustomizer customizer() {
        return new ArtemisConfigurationCustomizer() {
            @Override
            public void customize(org.apache.activemq.artemis.core.config.Configuration configuration) {
                try {
                    // 将localhost改为0.0.0.0,监听容器所有网卡接口
                    configuration.addAcceptorConfiguration("netty", "tcp://0.0.0.0:61616");
                }
                catch (Exception e) {
                    throw new RuntimeException("Failed to add netty transport acceptor to artemis instance", e);
                }
            }
       };
    }
}

如果是OpenWire协议的Acceptor配置,也按照相同规则,将绑定地址从localhost改为0.0.0.0即可。

修改完成后重新构建fat jar、重新打包Docker镜像,再启动容器即可从外部正常访问服务。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 13:45:02