From 978f7f1bdb3b5dd166d9bbc7362fff3ae0b57369 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Tue, 25 Feb 2025 17:55:12 +0800 Subject: [PATCH] =?UTF-8?q?mq=E9=98=9F=E5=88=97=20=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E7=AB=AF=20=E9=98=9F=E5=88=97=E5=AD=98?= =?UTF-8?q?=E6=B4=BB=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/czg/mq/RabbitmqReceiver.java | 88 +++++++++---------- .../java/com/czg/config/RabbitConfig.java | 4 +- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/cash-api/order-server/src/main/java/com/czg/mq/RabbitmqReceiver.java b/cash-api/order-server/src/main/java/com/czg/mq/RabbitmqReceiver.java index 854f30ca..c10c340f 100644 --- a/cash-api/order-server/src/main/java/com/czg/mq/RabbitmqReceiver.java +++ b/cash-api/order-server/src/main/java/com/czg/mq/RabbitmqReceiver.java @@ -1,44 +1,44 @@ -package com.czg.mq; - -import com.czg.config.RabbitConstants; -import com.rabbitmq.client.Channel; -import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.core.Message; -import org.springframework.amqp.rabbit.annotation.*; -import org.springframework.stereotype.Component; - -import java.io.IOException; - -/** - * @author GYJoker - */ -@Slf4j -@Component -public class RabbitmqReceiver { - - /** - * 消费者监听,绑定队列 - * Queue RabbitConfig类的 orderPrintQueue - */ - @RabbitListener( - bindings = @QueueBinding(value = @Queue(value = "#{orderPrintQueue.name}", durable = "true", - arguments = {@Argument(name = "x-message-ttl", value = "180000", type = "java.lang.Long")}), - exchange = @Exchange(value = RabbitConstants.Exchange.CASH_EXCHANGE)), - concurrency = "10" - ) - @RabbitHandler - public void receiveOrderPrintQueue(Channel channel, String orderId, Message message) throws IOException { - try { - log.info("订单监听 消息体:{},消息内容:{}", message, orderId); - // 手动确认消息,multiple 参数表示是否批量确认 - channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); - } catch (Exception e) { - log.error(e.getMessage(), e); - // 判断是否需要重新入队 - boolean requeue = false; - // 拒绝消息,requeue 为 true 表示将消息重新放回队列 - channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, requeue); - } - - } -} +//package com.czg.mq; +// +//import com.czg.config.RabbitConstants; +//import com.rabbitmq.client.Channel; +//import lombok.extern.slf4j.Slf4j; +//import org.springframework.amqp.core.Message; +//import org.springframework.amqp.rabbit.annotation.*; +//import org.springframework.stereotype.Component; +// +//import java.io.IOException; +// +///** +// * @author GYJoker +// */ +//@Slf4j +//@Component +//public class RabbitmqReceiver { +// +// /** +// * 消费者监听,绑定队列 +// * Queue RabbitConfig类的 orderPrintQueue +// */ +// @RabbitListener( +// bindings = @QueueBinding(value = @Queue(value = "#{orderPrintQueue.name}", durable = "true", +// arguments = {@Argument(name = "x-message-ttl", value = "180000", type = "java.lang.Long")}), +// exchange = @Exchange(value = RabbitConstants.Exchange.CASH_EXCHANGE)), +// concurrency = "10" +// ) +// @RabbitHandler +// public void receiveOrderPrintQueue(Channel channel, String orderId, Message message) throws IOException { +// try { +// log.info("订单监听 消息体:{},消息内容:{}", message, orderId); +// // 手动确认消息,multiple 参数表示是否批量确认 +// channel.basicAck(message.getMessageProperties().getDeliveryTag(), false); +// } catch (Exception e) { +// log.error(e.getMessage(), e); +// // 判断是否需要重新入队 +// boolean requeue = false; +// // 拒绝消息,requeue 为 true 表示将消息重新放回队列 +// channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, requeue); +// } +// +// } +//} diff --git a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java index 8cb57472..07a9067e 100644 --- a/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java +++ b/cash-common/cash-common-mq/src/main/java/com/czg/config/RabbitConfig.java @@ -25,8 +25,8 @@ public class RabbitConfig { Map args = new HashMap<>(); // 设置消息过期时间为 180000 毫秒(即 180 秒) args.put("x-message-ttl", 180000); -// return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, args); - return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, null); + return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, args); +// return new Queue(activeProfile + "-" + RabbitConstants.Queue.ORDER_PRINT_QUEUE, true, false, false, null); } @Bean