Files
TKDataSave/src/main/java/com/yupi/springbootinit/rabbitMQ/MQSender.java
Ziin a90c4a347d 1.增加插入数据时的 createTime字段 为 LocalDateTime
2.自动序列和反序列化 CreateTime 字段
3.修改rabbitMQ序列化方法,使其支持 LocalDateTime
2025-06-26 19:12:27 +08:00

49 lines
1.8 KiB
Java

package com.yupi.springbootinit.rabbitMQ;
import cn.hutool.core.date.DateTime;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.model.entity.NewHosts;
import com.yupi.springbootinit.model.entity.ServerBigBrother;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@Service
public class MQSender {
@Resource
private RabbitTemplate rabbitTemplate;
//方法:发送消息
public void hostsSend(List<NewHosts> list){
try {
// log.info("{} 接收到的消息数量----------->{}", DateTime.now(),list.size());
this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//指定你队列的名字
rabbitTemplate.convertAndSend("HOST_INFO_QUEUE",list);
}catch (Exception e){
throw new BusinessException(ErrorCode.QUEUE_ERROR);
}
}
//方法:发送消息
public void bigBrotherSend(ServerBigBrother bigBrothers){
try {
// log.info("{} 接收到的消息数量----------->{}", DateTime.now(),list.size());
// this.rabbitTemplate.setMessageConverter(new Jackson2JsonMessageConverter());
//指定你队列的名字
rabbitTemplate.convertAndSend("BIG_BROTHER_QUEUE",bigBrothers);
}catch (Exception e){
log.error(e.getMessage() );
throw new BusinessException(ErrorCode.QUEUE_ERROR);
}
}
}