rocketmq 连接异常 senddefaultimpl call timeout
- RocketMQ
- 时间:2022-10-18 17:27
- 6478人已阅读
简介
rocketmq 连接异常 senddefaultimpl call timeout
🔔🔔🔔好消息!好消息!🔔🔔🔔
有需要的朋友👉:联系凯哥
在使用Java发送rocketmq消息的时候。错误:rocketmq 连接异常 senddefaultimpl call timeout:

第一种情况:
修改broker 的配置如下,注意brokerIP1 这个配置必须有,不然 rocketmq-console 显示依然是内网地址
brokerIP1=外网ip #nameServer地址,分号分割 namesrvAddr=外网ip1:9876;外网ip2:9870
第二中情况:
如果链接的是docker中的mq的话,需要设置超时时间。因为可能是超时导致的。
public class SyncProducer {
public static void main(String[] args) throws Exception {
//1:创建消息生产者producer,并指定生产者组名
DefaultMQProducer producer = new DefaultMQProducer("group1");
//2:制定nameserver地址
producer.setNamesrvAddr("192.168.50.131:9876");
//设置发送超时时间:
producer.setSendMsgTimeout(10000);
//3:启动prodicer
producer.start();
//4:创建消息对象,指定主题Topic、Tag和消息体
for (int i = 0; i < 10; i++) {
Message message = new Message();
message.setTopic("base-sync-topic");
message.setTags("Tag1");
message.setBody(("from sync-main"+i).getBytes());
//5:发送消息
SendResult result = producer.send(message);
SendStatus status = result.getSendStatus();
String msgId = result.getMsgId();
int queueId = result.getMessageQueue().getQueueId();
String offsetMegId = result.getOffsetMsgId();
long offset = result.getQueueOffset();
String sendResultMsg = "同步消息第"+i+"个发送状态:"+status+"\t"+"消息id:"+msgId+"\t 消费者队列id:"+queueId +"\t offsetMegId:"+offsetMegId+"\t offset:"+offset;
System.out.println(sendResultMsg);
}
//6:关闭生产者producer
producer.shutdown();
}
}//设置发送超时时间: producer.setSendMsgTimeout(10000);
这个比较重要。凯哥设置了这个超时时间就ok了