|
@@ -1,32 +1,27 @@
|
|
|
package com.backendsys.modules.common.config.rabbitmq;
|
|
|
|
|
|
-import com.backendsys.modules.system.entity.SysUser;
|
|
|
import com.rabbitmq.client.Channel;
|
|
|
import org.springframework.amqp.core.*;
|
|
|
-import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.nio.charset.StandardCharsets;
|
|
|
|
|
|
/**
|
|
|
* 自定义监听器
|
|
|
*/
|
|
|
@Component
|
|
|
@Lazy(false)
|
|
|
-public class DemoListener {
|
|
|
+public class RabbitListener {
|
|
|
|
|
|
-// // 自动 ACK
|
|
|
+// // [监听] 自动 ACK
|
|
|
// @RabbitListener(id = "demoContainer", queues = "demo.queue", autoStartup = "false" )
|
|
|
// public void receive(SysUser sysUser) {
|
|
|
// System.out.println("收到消息: " + sysUser);
|
|
|
// }
|
|
|
|
|
|
|
|
|
-// // 手动 ACK
|
|
|
+// // [监听] 手动 ACK
|
|
|
// @RabbitListener(id = "demoContainer", queues = "demo.queue", ackMode = "MANUAL")
|
|
|
// public void receive(Message message, Channel channel) throws IOException, InterruptedException {
|
|
|
// try {
|
|
@@ -46,10 +41,10 @@ public class DemoListener {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- // 监听死信队列
|
|
|
- @RabbitListener(id = "dlxContainer", queues = "dlx.queue", ackMode = "MANUAL")
|
|
|
+ // [监听] 死信队列
|
|
|
+ @org.springframework.amqp.rabbit.annotation.RabbitListener(id = "dlxContainer", queues = "dlx.queue", ackMode = "MANUAL")
|
|
|
public void handleDlx(Message message, Channel channel) throws IOException {
|
|
|
- System.out.println("【死信】收到:" + new String(message.getBody()));
|
|
|
+ System.out.println("【RabbitMQ-死信】收到:" + new String(message.getBody()));
|
|
|
|
|
|
// 业务:记录日志 / 重发 / 报警 / 人工补偿
|
|
|
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|