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