一、代码重现如下:
二、错误描述:
com.alibaba.rocketmq.client.exception.MQClientException: Send [1] times, still failed, cost [6340]ms, Topic: topic_canDetail, BrokersSent: [broker-b, null, null]
See http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&send_msg_failed for further details.
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:485)
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:964)
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:928)
at com.alibaba.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:92)
at com.chainawy.rocketmq.Producer.main(Producer.java:22)
Caused by: com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <> failed
at com.alibaba.rocketmq.remoting.netty.NettyRemotingClient.invokeSync(NettyRemotingClient.java:355)
at com.alibaba.rocketmq.client.impl.MQClientAPIImpl.sendMessageSync(MQClientAPIImpl.java:270)
at com.alibaba.rocketmq.client.impl.MQClientAPIImpl.sendMessage(MQClientAPIImpl.java:253)
at com.alibaba.rocketmq.client.impl.MQClientAPIImpl.sendMessage(MQClientAPIImpl.java:216)
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendKernelImpl(DefaultMQProducerImpl.java:611)
at com.alibaba.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:413)
... 4 more
三、消息发送失败的原因:
1. 目前这种写法Rocket默认开启了VIP通道,VIP通道端口为10911-2=10909。若Rocket服务器未启动端口10909,则报connect to <> failed。
2. 解决方式:增加一行代码producer.setVipChannelEnabled(false);