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()); } }