houzhongjian
2024-11-07 191b3de92e362123e6d4d77d56e76c6d44fa4374
增加截图成功后发送rabbitMQ消息
已修改3个文件
已添加7个文件
219 ■■■■■ 文件已修改
iailab-framework/iailab-common-mq/src/main/java/com/iailab/framework/mq/common/RoutingConstant.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/pom.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/config/TopicImageRabbitConfig.java 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/consumer/ImageConsumer.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/consumer/ImageMessage.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/package-info.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/data/controller/RabbitMQTest.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/data/package-info.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/package-info.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
iailab-framework/iailab-common-mq/src/main/java/com/iailab/framework/mq/common/RoutingConstant.java
@@ -10,4 +10,13 @@
public interface RoutingConstant {
    String Iailab_Data_PointCollectFinish = "Iailab.Data.PointCollectFinish";
    // 摄像头通配路由
    String Iailab_Data_Image = "Iailab.Data.Image.*";
    // 大华摄像头路由
    String Iailab_Data_Image_Dahua = "Iailab.Data.Image.Dahua";
    // 海康摄像头路由
    String Iailab_Data_Image_Hikvision = "Iailab.Data.Image.Hikvision";
}
iailab-module-data/iailab-module-data-biz/pom.xml
@@ -60,10 +60,10 @@
            <artifactId>iailab-common-biz-ip</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>com.iailab</groupId>-->
<!--            <artifactId>iailab-common-mq</artifactId>-->
<!--        </dependency>-->
        <dependency>
            <groupId>com.iailab</groupId>
            <artifactId>iailab-common-mq</artifactId>
        </dependency>
        <!-- Web 相关 -->
        <dependency>
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/config/TopicImageRabbitConfig.java
对比新文件
@@ -0,0 +1,48 @@
package com.iailab.module.data.mq.config;
import com.iailab.module.data.mq.consumer.ImageMessage;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
 * @author Houzhongjian
 * @Description
 * @createTime 2024年11月06日
 */
@Configuration
public class TopicImageRabbitConfig {
    //绑定键
    public final static String routingDahua = ImageMessage.DAHUA_ROUTING_KEY;
    public final static String routingHikvison = ImageMessage.HIKVISION_ROUTING_KEY;
    @Bean
    public Queue imageDahuaQueue() {
        return new Queue(TopicImageRabbitConfig.routingDahua);
    }
    @Bean
    public Queue imageHikvisionQueue() {
        return new Queue(TopicImageRabbitConfig.routingHikvison);
    }
    @Bean
    TopicExchange exchange() {
        return new TopicExchange(ImageMessage.EXCHANGE);
    }
    // 注意通配符*和#的用法
    @Bean
    Binding bindingExchangeMessageDH() {
        return BindingBuilder.bind(imageDahuaQueue()).to(exchange()).with(routingDahua);
    }
    @Bean
    Binding bindingExchangeMessageHK() {
        return BindingBuilder.bind(imageHikvisionQueue()).to(exchange()).with(routingHikvison);
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/consumer/ImageConsumer.java
对比新文件
@@ -0,0 +1,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());
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/consumer/ImageMessage.java
对比新文件
@@ -0,0 +1,37 @@
package com.iailab.module.data.mq.consumer;
import com.iailab.framework.mq.common.RoutingConstant;
import com.iailab.module.data.video.dto.ImageDTO;
import lombok.Data;
import java.io.Serializable;
@Data
public class ImageMessage implements Serializable {
    //暂时取消queue,使用routing自动生成
//    public static final String QUEUE = "topic.image";
    public static final String EXCHANGE = "imageExchange";
    public static final String ROUTING_KEY = RoutingConstant.Iailab_Data_Image;
    public static final String DAHUA_ROUTING_KEY = RoutingConstant.Iailab_Data_Image_Dahua;
    public static final String HIKVISION_ROUTING_KEY = RoutingConstant.Iailab_Data_Image_Hikvision;
    private String messageId;
    private String createTime;
    private ImageDTO imageDTO;
    @Override
    public String toString() {
        return "ImageMessage{" +
                "messageId='" + messageId + '\'' +
                ", createTime='" + createTime + '\'' +
                ", imageDTO=" + imageDTO +
                '}';
    }
}
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/mq/package-info.java
对比新文件
@@ -0,0 +1 @@
package com.iailab.module.data.mq;
iailab-module-data/iailab-module-data-biz/src/main/java/com/iailab/module/data/video/service/impl/CameraServiceImpl.java
@@ -106,13 +106,7 @@
        image.setCreateDate(captureDate);
        imageDao.insert(image);
        //存入rabbitmq消息队列,等待模型处理
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ImageMessage imageMessage = new ImageMessage();
        imageMessage.setMessageId(image.getId());
        imageMessage.setCreateTime(createTime);
        imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class));
        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.ROUTING_KEY, imageMessage);
//        rabbitTemplate.convertAndSend("topic.image", imageMap);
        sendRabbitMQMessage(image);
    }
    private QueryWrapper<CameraEntity> getWrapper(CameraPageReqVO cameraPageReqVO){
@@ -155,4 +149,14 @@
        return baseDao.selectCount(queryWrapper);
    }
    // 发送rabbitMQ消息
    private void sendRabbitMQMessage(ImageEntity image) {
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        ImageMessage imageMessage = new ImageMessage();
        imageMessage.setMessageId(image.getId());
        imageMessage.setCreateTime(createTime);
        imageMessage.setImageDTO(BeanUtils.toBean(image, ImageDTO.class));
        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.DAHUA_ROUTING_KEY, imageMessage);
    }
}
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/data/controller/RabbitMQTest.java
对比新文件
@@ -0,0 +1,36 @@
package com.iailab.module.data.controller;
import com.iailab.DataWebApplication;
import com.iailab.framework.test.core.ut.BaseMockitoUnitTest;
import com.iailab.module.data.mq.consumer.ImageMessage;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.test.context.SpringBootTest;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
 * @author Houzhongjian
 * @Description
 * @createTime 2024年11月06日
 */
@SpringBootTest(classes = DataWebApplication.class)
public class RabbitMQTest extends BaseMockitoUnitTest {
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Test
    public void testProducer() {
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> imageMap = new HashMap<>();
        imageMap.put("messageId", "111111111111111");
        imageMap.put("image", "8888888888888888888");
        imageMap.put("createTime", createTime);
        rabbitTemplate.convertAndSend(ImageMessage.EXCHANGE, ImageMessage.ROUTING_KEY, imageMap);
    }
}
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/data/package-info.java
对比新文件
@@ -0,0 +1 @@
package com.iailab.module.data;
iailab-module-data/iailab-module-data-biz/src/test/java/com/iailab/module/package-info.java
对比新文件
@@ -0,0 +1 @@
package com.iailab.module;