| | |
| | | import org.springframework.amqp.core.Message; |
| | | import org.springframework.amqp.rabbit.annotation.RabbitListener; |
| | | import org.springframework.amqp.rabbit.core.RabbitTemplate; |
| | | import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener; |
| | | import org.springframework.stereotype.Component; |
| | | import org.yeshi.utils.StringUtil; |
| | | |
| | |
| | | * @description: 延时队列消费处理 |
| | | * @date 2024/10/12 11:21 |
| | | */ |
| | | //@Component |
| | | public class RabbitDelayConsumer { |
| | | public class RabbitDelayConsumer implements ChannelAwareMessageListener { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger("infoLog"); |
| | | private Logger logger = LoggerFactory.getLogger("infoLog"); |
| | | |
| | | @Resource |
| | | private RabbitTemplate rabbitTemplate; |
| | | |
| | | |
| | | // @RabbitListener(queues = RabbitmqSenderUtil.DELAY_QUEUE_NAME, ackMode = "MANUAL") |
| | | @Override |
| | | public void onMessage(Message message, Channel channel) throws Exception { |
| | | String msg = new String( message.getBody(), StandardCharsets.UTF_8); |
| | | logger.info("RabbitDelayConsumer-{}",msg); |
| | | DelayMsgInfo msgInfo = new Gson().fromJson(msg, DelayMsgInfo.class); |
| | | if(!StringUtil.isNullOrEmpty(msgInfo.getQueueName())){ |
| | | // 队列消息 |
| | | String msg = new String(message.getBody(), StandardCharsets.UTF_8); |
| | | logger.info("RabbitDelayConsumer-{}", msg); |
| | | DelayMsgInfo msgInfo = new Gson().fromJson(msg, DelayMsgInfo.class); |
| | | if (!StringUtil.isNullOrEmpty(msgInfo.getQueueName())) { |
| | | // 队列消息 |
| | | RabbitmqSenderUtil.sendQueueMsg(rabbitTemplate, msgInfo.getQueueName(), msgInfo.getMsg()); |
| | | }else{ |
| | | } else { |
| | | // 交换机消息 |
| | | RabbitmqSenderUtil.sendExchangeMsg(rabbitTemplate, msgInfo.getExchangeName(), msgInfo.getRoutingKey(), msgInfo.getMsg()); |
| | | } |