写mq消息失败

发布时间 2023-12-19 18:05:31作者: 借你耳朵说爱你

 

有时候解决问题的方式很简单,如下:
消费模式:
        集群模式
普通消息:
        单向发送
pom.xml配置

<dependency>
    <groupId>org.apache.rocketmq</groupId>
    <artifactId>rocketmq-spring-boot-starter</artifactId>
    <version>2.0.4</version>
</dependency>

1. 使用下面代码向mq写消息

rocketMQTemplate.convertAndSend(message.getMqTopic(), message.getMqMessage());

1.1 yaml配置文件内容

rocketmq:
  name-server: ip:端口
  producer:
    group: "G-Group_REQ"
    send-msg-timeout: 30000

1.2 报错:sendDefaultImpl call timeout; nested exception is org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout


2. 使用下面代码

DefaultMQProducer producer = new DefaultMQProducer(message.getMqGroup());
producer.setNamesrvAddr(namesrvAddr);
producer.setSendMsgTimeout(30000);
producer.start();
Message msg = new Message(message.getMqTopic(), message.getMqMessage().getBytes());
producer.send(msg);

2.1 yaml配置文件内容

rocketmq:
  name-server: ip:端口

2.2 报错:Send [3] times, still failed, cost [9490]ms, Topic: T-costcont-WelfareCostApproval, BrokersSent: [a, a, a]
See http://rocketmq.apache.org/docs/faq/ for further details.
2.3 报错:The producer group[G-costcont-WelfareCostApproval_REQ] has been created before, specify another name please.
See http://rocketmq.apache.org/docs/faq/ for further details.


3. 官方解释:
3.1 SEND_MSG_FAILED
异常信息
       Send [xxx] times, still failed, cost [xxx]ms, Topic: xxx, BrokersSent ...
原因
       1)Producer消息发送异常。在 SYNC 模式下总共发送 3 次,在 ASYNC 和 ONEWAY 模式下发送 1 次。
解决方法
       1)Producer发送消息的timeout参数是否过小。
       2)确保Broker正常。
       3)确保 Producer 和 Broker 之间的连接正常。
3.2 GROUP_NAME_DUPLICATE_URL
异常信息
       The producer group[xxx] has been created before, specify another name please.
原因
       1)同名消费组已启动,注册失败。
解决方法
       1)重命名新的消费者组。
       2)同名的消费者组常闭,然后重新开始。


最终多方排查是:Producer 和 Broker 之间的连接问题,切换环境执行就没问题了。