Browse Source

打印日志

yq 2 years ago
parent
commit
fc4c0b2191

+ 5 - 6
src/main/java/com/usky/dxtop/service/config/rabbitmq/RabbitmqConfig.java

@@ -1,8 +1,7 @@
 package com.usky.dxtop.service.config.rabbitmq;
 
-import com.usky.dxtop.model.MsgLog;
+import com.usky.dxtop.common.utils.DateUtils;
 import com.usky.dxtop.service.MsgLogService;
-import com.usky.dxtop.service.emun.MsgLogStatus;
 import lombok.Data;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.core.AcknowledgeMode;
@@ -19,6 +18,7 @@ import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
 import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
 import org.springframework.context.annotation.Configuration;
 
+import java.util.Date;
 import java.util.Optional;
 
 /**
@@ -71,15 +71,14 @@ public class RabbitmqConfig {
         // 消息是否成功发送到Exchange
         rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
             if (ack) {
-                Optional.ofNullable(correlationData)
-                        .ifPresent(corre -> Optional.ofNullable(corre.getId())
-                                .ifPresent(id -> {
+                Optional.ofNullable(correlationData).flatMap(corre -> Optional.ofNullable(corre.getId())).ifPresent(id -> {
+                    log.info("消息成功发送到交换机+id:" + id + "时间:" + DateUtils.format(new Date(), null));
 //                                    String msgId = corre.getId();
 //                                    MsgLog msgLog = new MsgLog();
 //                                    msgLog.setId(Long.parseLong(msgId));
 //                                    msgLog.setMsgFlag(MsgLogStatus.DELIVER_SUCCESS.getCode());
 //                                    msgLogService.updateById(msgLog);
-                                }));
+                });
             } else {
                 log.error("消息发送到Exchange失败, {}, cause: {}", correlationData, cause);
             }