Commit 6bc5c8ba by 周晓航

新增保存发送消息体 用于补偿发送使用

parent e4bd032b
package cn.freemud.amp.service;
import lombok.Data;
import org.springframework.amqp.rabbit.connection.CorrelationData;
/**
* @author : xh.Z
* @email : fisherman0510@163.com
* @Date : 2022/8/25 11:00
* @description :
*/
@Data
public class MyCorrelationData extends CorrelationData {
private String myContent;
}
package cn.freemud.amp.service; package cn.freemud.amp.service;
import cn.freemud.amqp.FastJsonMessageConverter; import cn.freemud.amqp.FastJsonMessageConverter;
import cn.freemud.amqp.MQMessage;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.freemud.application.sdk.api.ordercenter.entities.vo.OrderCallBackRequestVo;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory;
...@@ -40,8 +43,9 @@ public class SendMQConfirmCallback { ...@@ -40,8 +43,9 @@ public class SendMQConfirmCallback {
public void convertAndSend(String exchange, String queueName, final Object object) { public void convertAndSend(String exchange, String queueName, final Object object) {
CorrelationData data = new CorrelationData(); MyCorrelationData data = new MyCorrelationData();
data.setId(JSON.toJSONString(data)); data.setId(System.currentTimeMillis() + "");
data.setMyContent(JSON.toJSONString(object));
this.rabbitTemplate.convertAndSend(exchange, queueName, object, data); this.rabbitTemplate.convertAndSend(exchange, queueName, object, data);
} }
...@@ -65,6 +69,10 @@ public class SendMQConfirmCallback { ...@@ -65,6 +69,10 @@ public class SendMQConfirmCallback {
*/ */
@Override @Override
public void confirm(CorrelationData correlationData, boolean ack, String cause) { public void confirm(CorrelationData correlationData, boolean ack, String cause) {
String id = correlationData.getId();
MyCorrelationData data = (MyCorrelationData) correlationData;
MQMessage<OrderCallBackRequestVo> orderCallBackRequestVoMQMessage = JSON.parseObject(data.getMyContent(), new TypeReference<MQMessage<OrderCallBackRequestVo>>() {
});
log.info("消息ID:{},消息是否到达Broker:{},失败信息:{}", correlationData, ack, cause); log.info("消息ID:{},消息是否到达Broker:{},失败信息:{}", correlationData, ack, cause);
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment