RocketMQ一直打印RocketmqRemoting closeChannel: close the connection to remote address[] result: true

交代一下背景:

RocketMQ服务端搭建在ECS上面(问题就出在这里)

SpringBoot应用根据官网Demo(参考:https://github.com/apache/rocketmq-spring/tree/master/rocketmq-spring-boot-samples)构建

 

项目启动的时候就开始打印远程地址为空,发送消息失败并且也打印远程地址为空:

RocketmqRemoting: closeChannel: close the connection to remote address[] result: true

 

remote address是空的,开始以为是项目的rocketmq.name-server配置有问题,通过获取RocketMQTemplate的namesrvAddr发现没问题,代码如下

rocketMQTemplate.getProducer().getNamesrvAddr()

 

再看一下SendCallback的Throwable,错误信息如下:

org.apache.rocketmq.client.exception.MQClientException: Send [1] times, still failed, cost [5325]ms, Topic: ADDRESS_PART_TOPIC, BrokersSent: [broker-a]
See http://rocketmq.apache.org/docs/faq/ for further details.
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:638)
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.access$300(DefaultMQProducerImpl.java:90)
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl$3.run(DefaultMQProducerImpl.java:491)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.rocketmq.remoting.exception.RemotingConnectException: connect to <192.168.0.4:10911> failed
    at org.apache.rocketmq.remoting.netty.NettyRemotingClient.invokeAsync(NettyRemotingClient.java:537)
    at org.apache.rocketmq.client.impl.MQClientAPIImpl.sendMessageAsync(MQClientAPIImpl.java:484)
    at org.apache.rocketmq.client.impl.MQClientAPIImpl.sendMessage(MQClientAPIImpl.java:441)
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendKernelImpl(DefaultMQProducerImpl.java:811)
    at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:557)
    ... 8 more

看到192.168.0.4:10911这个地址就知道问题是出在RocketMQ的Broker服务,192.168.0.4是ECS内网IP地址

这里再看一下Broker启动信息:

 

The broker[broker-a, 192.168.0.4:10911] boot success. serializeType=JSON and name server is X.X.X.X:9876

 

确定问题是brokerIP是服务器的内网IP导致producer无法与之建立连接导致

 

解决方法:

 

//查看broker配置
sh ./bin/mqbroker -m

 

在conf/broker.conf配置文件中增加

 

brokerIP1=X.X.X.X(公网IP)

 

再次启动broker服务

nohup sh bin/mqbroker -n 111.231.XX.XX:9876 -c conf/broker.conf autoCreateTopicEnable=true &

启动结果:

The broker[broker-a, X.X.X.X:10911] boot success. serializeType=JSON and name server is 106.12.x.x:9876

重启本地项目,测试producer发送消息成功

posted @ 2019-11-27 16:04  codest  阅读(39610)  评论(2编辑  收藏  举报