潘志宝
2024-11-08 05a1bbf8c7f01498d084b04c30652bb685b333bb
提交 | 用户 | 时间
191b3d 1 package com.iailab.module.data.mq.consumer;
H 2
3 import org.springframework.amqp.core.ExchangeTypes;
4 import org.springframework.amqp.rabbit.annotation.*;
5 import org.springframework.stereotype.Component;
6
7 import java.util.Date;
8
9 /**
10  * @author Houzhongjian
11  * @Description
12  * @createTime 2024年11月05日
13  */
14 @Component
15 @RabbitListener(
16         bindings = @QueueBinding(
17                 value = @Queue(
18                         // 在 Queue 的名字上,使用 UUID 生成其后缀。这样,启动的 Consumer 的 Queue 不同,以达到广播消费的目的
19                         name = ImageMessage.DAHUA_ROUTING_KEY,
20                         // Consumer 关闭时,该队列就可以被自动删除了
21                         autoDelete = "true"
22                 ),
23                 exchange = @Exchange(
24                         name = ImageMessage.EXCHANGE,
25                         type = ExchangeTypes.TOPIC,
26                         declare = "false",
27                         autoDelete = "true"
28                 )
29         )
30 )
31 @RabbitListener(
32         bindings = @QueueBinding(
33                 value = @Queue(
34                         // 在 Queue 的名字上,使用 UUID 生成其后缀。这样,启动的 Consumer 的 Queue 不同,以达到广播消费的目的
35                         name = ImageMessage.HIKVISION_ROUTING_KEY,
36                         // Consumer 关闭时,该队列就可以被自动删除了
37                         autoDelete = "true"
38                 ),
39                 exchange = @Exchange(
40                         name = ImageMessage.EXCHANGE,
41                         type = ExchangeTypes.TOPIC,
42                         declare = "false",
43                         autoDelete = "true"
44                 )
45         )
46 )
47 public class ImageConsumer {
48
49 //    @RabbitHandler
50     public void process(ImageMessage imageMessage) throws InterruptedException {
51         System.out.println("1111111111111111111111111");
52         Thread.sleep(5000);
53         System.out.println(imageMessage.toString());
54         System.out.println(new Date());
55         System.out.println(imageMessage.getCreateTime());
56         System.out.println(imageMessage.getMessageId());
57         System.out.println(imageMessage.getImageDTO().getImagePath());
58     }
59
60 }