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

Spring Web应用创建Corda RPC代理时遇ActiveMQ超时连接错误

Corda RPC代理连接ActiveMQ超时问题排查与解决

嘿,我来帮你搞定这个Spring Web应用连接Corda RPC时遇到的ActiveMQ超时问题。先把核心错误和堆栈信息理清楚,再一步步排查:

核心错误信息

你遇到的关键错误是:

ActiveMQConnectionTimedOutException[ errorType=CONNECTION_TIMEDOUT message=AMQ119013: Timed out waiting to receive cluster topology. Group:null ]

伴随的根源错误是:

ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]

完整堆栈跟踪(截取关键部分):

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'nodeController' defined in file [D:\Development\acme\acme-tech\acme-tech-spring\out\production\classes\com\acme\tech\spring\controllers\NodeController.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.acme.tech.spring.controllers.NodeController]: Constructor threw exception; nested exception is ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1155) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
...
Caused by: org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException: AMQ119007: Cannot connect to server(s). Tried with all available servers.
    at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:787) ~[artemis-core-client-2.0.0.jar:2.0.0]
    at net.corda.client.rpc.internal.RPCClientProxyHandler.start(RPCClientProxyHandler.kt:191) ~[corda-rpc-3.1-corda.jar:na]

一步步排查解决方案

1. 先确认Corda节点状态与RPC配置

  • 首先检查你的Corda节点是否真的启动成功了!去节点的日志目录看看,有没有类似Node for "PartyA" started up and registered in X seconds的成功提示,如果节点还在启动中或者启动失败,肯定连不上。
  • 核对Spring应用里的RPC连接参数和节点node.conf的配置:
    • 确认RPC地址(比如localhost:10006)和节点rpcSettings.address完全一致,不同节点的RPC端口不一样,别搞混了!
    • 确认你用的用户名和密码在节点rpcUsers列表里存在,密码也得匹配,不然会被拒绝连接。

2. 排查网络与防火墙问题

  • 如果是远程连接节点,先测试端口连通性,用telnet或者nc命令试试:
    telnet localhost 10006
    
    如果连不上,要么是防火墙挡住了这个端口,要么是网络路由有问题,得先把网络打通。

3. 检查ActiveMQ客户端版本兼容性

  • 从堆栈里看到你用的是artemis-core-client-2.0.0,但Corda 3.1依赖的是ActiveMQ Artemis 1.x版本,版本不兼容会直接导致连接失败。
  • 建议让Corda的corda-rpc依赖自动管理Artemis版本,别手动引入高版本的Artemis客户端。如果是Gradle/Maven,确保corda-rpc是直接引入的,不要覆盖它的依赖版本。

4. 调整Spring Bean初始化时机

  • 你在NodeController的构造函数里初始化RPC代理,这会导致Spring一启动就尝试连接节点,如果此时节点还没完全就绪,就会超时。
  • 改成用@PostConstruct延迟初始化,或者在第一次接口调用时再建立连接,还可以加个重试机制:
    @RestController
    class NodeController {
        private lateinit var rpcProxy: CordaRPCOps
    
        @PostConstruct
        fun initRpcConnection() {
            val rpcAddress = NetworkHostAndPort("localhost", 10006)
            val rpcClient = RPCClient(rpcAddress)
            // 这里可以加个重试逻辑,比如循环尝试3次
            val rpcConnection = rpcClient.start("your-rpc-user", "your-rpc-password")
            this.rpcProxy = rpcConnection.proxy
        }
    }
    

5. 检查Corda节点的RPC连接限制

  • 看看节点node.conf里的rpcSettings.maximumConcurrentCalls等配置,是不是设置的连接数太小,导致新连接被拒绝。如果连接数满了,也会出现无法连接的错误,可以适当调大这个值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 06:55:35