Skip to content

Commit cfe64b6

Browse files
committed
feat: RabbitMQ 消息回调添加处理钩子
1 parent 440e860 commit cfe64b6

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

  • common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/rabbit

common/plugin/mq/src/main/java/com/github/cadecode/uniboot/common/plugin/mq/rabbit/RabbitCallback.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.hutool.core.util.ObjectUtil;
44
import com.github.cadecode.uniboot.common.plugin.mq.consts.RabbitConst;
5+
import com.github.cadecode.uniboot.common.plugin.mq.handler.AbstractTxMsgHandler;
56
import lombok.RequiredArgsConstructor;
67
import lombok.extern.slf4j.Slf4j;
78
import org.springframework.amqp.core.Exchange;
@@ -37,6 +38,8 @@ public class RabbitCallback implements ConfirmCallback, ReturnsCallback, Initial
3738

3839
private final RabbitTemplate rabbitTemplate;
3940

41+
private final AbstractTxMsgHandler txMsgTaskHandler;
42+
4043
/**
4144
* 消息是否成功到达交换机
4245
*/
@@ -46,9 +49,11 @@ public void confirm(CorrelationData correlationData, boolean ack, String cause)
4649
String correlationId = ObjectUtil.defaultIfNull(correlationData, CorrelationData::getId, "");
4750
if (ack) {
4851
log.debug("Rabbit message send ok, id:{}", correlationId);
52+
txMsgTaskHandler.handleConfirm(correlationData, true, cause);
4953
return;
5054
}
5155
log.error("Rabbit message send fail, correlationId:{}, cause:{}", correlationId, cause);
56+
txMsgTaskHandler.handleConfirm(correlationData, false, cause);
5257
}
5358

5459
/**
@@ -62,6 +67,7 @@ public void returnedMessage(ReturnedMessage returned) {
6267
}
6368
log.error("Rabbit message is returned, message:{}, replyCode:{}. replyText:{}, exchange:{}, routingKey :{}",
6469
returned.getMessage(), returned.getReplyCode(), returned.getReplyText(), returned.getExchange(), returned.getRoutingKey());
70+
txMsgTaskHandler.handleReturned(returned);
6571
}
6672

6773
/**

0 commit comments

Comments
 (0)