소스 검색

mq做负载

tags/正式版本
雍文秀 2 년 전
부모
커밋
b8693c16e1

+ 22
- 7
sapi/src/main/java/com/xhkjedu/sapi/config/RabbitConfig.java 파일 보기

@@ -13,30 +13,45 @@ import org.springframework.context.annotation.Configuration;
13 13
  **/
14 14
 @Configuration
15 15
 public class RabbitConfig {
16
+    //消费者mq
17
+    @Value("${rabbitmq.researchHandleQueue}")
18
+    private String researchHandleQueue;
16 19
 
20
+    //负载一生产者mq
17 21
     @Value("${rabbitmq.researchTransferQueue}")
18 22
     private String researchTransferQueue;
19
-
20 23
     @Value("${rabbitmq.resourceDelQueue}")
21 24
     private String resourceDelQueue;
22 25
 
23
-    @Value("${rabbitmq.researchHandleQueue}")
24
-    private String researchHandleQueue;
26
+    //负载二生产者mq
27
+    @Value("${rabbitmq.researchTransferQueue2}")
28
+    private String researchTransferQueue2;
29
+    @Value("${rabbitmq.resourceDelQueue2}")
30
+    private String resourceDelQueue2;
25 31
 
32
+    //消费者mq
33
+    @Bean
34
+    public Queue researchHandleQueue() {
35
+        return new Queue(researchHandleQueue);
36
+    }
26 37
 
38
+    //负载一生产者mq
27 39
     @Bean
28 40
     public Queue researchTransferQueue() {
29 41
         return new Queue(researchTransferQueue);
30 42
     }
31
-
32 43
     @Bean
33 44
     public Queue resourceDelQueue() {
34 45
         return new Queue(resourceDelQueue);
35 46
     }
36 47
 
48
+    //负载二生产者mq
37 49
     @Bean
38
-    public Queue researchHandleQueue() {
39
-        return new Queue(researchHandleQueue);
50
+    public Queue researchTransferQueue2() {
51
+        return new Queue(researchTransferQueue2);
52
+    }
53
+    @Bean
54
+    public Queue resourceDelQueue2() {
55
+        return new Queue(resourceDelQueue2);
40 56
     }
41
-
42 57
 }

+ 18
- 2
sapi/src/main/java/com/xhkjedu/sapi/listener/MessageSender.java 파일 보기

@@ -20,21 +20,37 @@ import java.util.Map;
20 20
 public class MessageSender {
21 21
     @Autowired
22 22
     private AmqpTemplate rabbitTemplate;
23
+    //负载一生产者mq
23 24
     @Value("${rabbitmq.researchTransferQueue}")
24 25
     private String researchTransferQueue;
25 26
     @Value("${rabbitmq.resourceDelQueue}")
26 27
     private String resourceDelQueue;
28
+    //负载二生产者mq
29
+    @Value("${rabbitmq.researchTransferQueue2}")
30
+    private String researchTransferQueue2;
31
+    @Value("${rabbitmq.resourceDelQueue2}")
32
+    private String resourceDelQueue2;
33
+    //负载一节点名称
34
+    private final String node2="node02/";
27 35
 
28 36
     //教研视频转换mq
29 37
     public void convertVideo(Integer resourceid, String resourceurl) {
30 38
         Map map = new HashMap();
31 39
         map.put("resourceid",resourceid);
32 40
         map.put("resourceurl",resourceurl);
33
-        rabbitTemplate.convertAndSend(researchTransferQueue, JSON.toJSONString(map));
41
+        if (resourceurl.contains(node2)) {
42
+            rabbitTemplate.convertAndSend(researchTransferQueue2, JSON.toJSONString(map));
43
+        } else {
44
+            rabbitTemplate.convertAndSend(researchTransferQueue, JSON.toJSONString(map));
45
+        }
34 46
     }
35 47
 
36 48
     //资源删除mq
37 49
     public void resourceDel(List<String> resourceurls) {
38
-        rabbitTemplate.convertAndSend(resourceDelQueue,JSON.toJSONString(resourceurls));
50
+        if (resourceurls.toString().contains(node2)) {
51
+            rabbitTemplate.convertAndSend(resourceDelQueue2, JSON.toJSONString(resourceurls));
52
+        } else {
53
+            rabbitTemplate.convertAndSend(resourceDelQueue, JSON.toJSONString(resourceurls));
54
+        }
39 55
     }
40 56
 }

+ 7
- 2
sapi/src/main/resources/application.properties 파일 보기

@@ -49,9 +49,14 @@ spring.redis.jedis.pool.max-active=60000
49 49
 redisdatatime=604800
50 50
 #secretKey必须为24位
51 51
 secretKey=nanhuakaizhangjianwangni
52
-rabbitmq.researchTransferQueue=xhkjedutest.xhschool.researchTransferQueue_dev
53
-rabbitmq.resourceDelQueue=xhkjedutest.xhschool.resourceDelQueue_dev
52
+#消费者mq
54 53
 rabbitmq.researchHandleQueue=xhkjedutest.xhschool.researchHandleQueue_dev
54
+#负载一生产者mq
55
+rabbitmq.researchTransferQueue=xhkjedutest.xhschool.researchTransferQueue_node01_dev
56
+rabbitmq.resourceDelQueue=xhkjedutest.xhschool.resourceDelQueue_node01_dev
57
+#负载二生产者mq
58
+#rabbitmq.researchTransferQueue2=xhkjedutest.xhschool.researchTransferQueue_node02_dev
59
+#rabbitmq.resourceDelQueue2=xhkjedutest.xhschool.resourceDelQueue_node02_dev
55 60
 spring.rabbitmq.host=49.4.26.249
56 61
 spring.rabbitmq.port=5672
57 62
 spring.rabbitmq.username=xhkjedu

+ 45
- 21
sexam/src/main/java/com/xhkjedu/sexam/config/RabbitConfig.java 파일 보기

@@ -13,51 +13,75 @@ import org.springframework.context.annotation.Configuration;
13 13
  **/
14 14
 @Configuration
15 15
 public class RabbitConfig {
16
+    //消费者mq
17
+    @Value("${rabbitmq.examImgMergeHandleQueue}")
18
+    private String examImgMergeHandleQueue;
19
+    @Value("${rabbitmq.examBaseToPdfHandleQueue}")
20
+    private String examBaseToPdfHandleQueue;
21
+    @Value("${rabbitmq.examBaseToScanImgHandleQueue}")
22
+    private String examBaseToScanImgHandleQueue;
23
+    @Value("${rabbitmq.examImgToPdfHandleQueue}")
24
+    private String examImgToPdfHandleQueue;
16 25
 
26
+    //负载一生产者mq
17 27
     @Value("${rabbitmq.examImgMergeQueue}")
18 28
     private String examImgMergeQueue;
19
-    @Value("${rabbitmq.examImgMergeHandleQueue}")
20
-    private String examImgMergeHandleQueue;
21 29
     @Value("${rabbitmq.examBaseToPdfQueue}")
22 30
     private String examBaseToPdfQueue;
23
-    @Value("${rabbitmq.examBaseToPdfHandleQueue}")
24
-    private String examBaseToPdfHandleQueue;
25 31
     @Value("${rabbitmq.examBaseToScanImgQueue}")
26 32
     private String examBaseToScanImgQueue;
27
-    @Value("${rabbitmq.examBaseToScanImgHandleQueue}")
28
-    private String examBaseToScanImgHandleQueue;
29 33
     @Value("${rabbitmq.examImgToPdfQueue}")
30 34
     private String examImgToPdfQueue;
31
-    @Value("${rabbitmq.examImgToPdfHandleQueue}")
32
-    private String examImgToPdfHandleQueue;
33 35
 
34
-    @Bean
35
-    public Queue examImgMergeQueue() {
36
-        return new Queue(examImgMergeQueue);
37
-    }
36
+    //负载二生产者mq
37
+    @Value("${rabbitmq.examImgMergeQueue2}")
38
+    private String examImgMergeQueue2;
39
+    @Value("${rabbitmq.examBaseToPdfQueue2}")
40
+    private String examBaseToPdfQueue2;
41
+    @Value("${rabbitmq.examBaseToScanImgQueue2}")
42
+    private String examBaseToScanImgQueue2;
43
+    @Value("${rabbitmq.examImgToPdfQueue2}")
44
+    private String examImgToPdfQueue2;
38 45
 
46
+    //消费者mq
39 47
     @Bean
40 48
     public Queue examImgMergeHandleQueue() {
41 49
         return new Queue(examImgMergeHandleQueue);
42 50
     }
43
-
44
-    @Bean
45
-    public Queue examBaseToPdfQueue() {
46
-        return new Queue(examBaseToPdfQueue);
47
-    }
48
-
49 51
     @Bean
50 52
     public Queue examBaseToPdfHandleQueue() {
51 53
         return new Queue(examBaseToPdfHandleQueue);
52 54
     }
55
+    @Bean
56
+    public Queue examBaseToScanImgHandleQueue(){ return new Queue(examBaseToScanImgHandleQueue);}
57
+    @Bean
58
+    public Queue examImgToPdfHandleQueue(){ return new Queue(examImgToPdfHandleQueue);}
53 59
 
60
+    //负载一生产者mq
61
+    @Bean
62
+    public Queue examImgMergeQueue() {
63
+        return new Queue(examImgMergeQueue);
64
+    }
65
+    @Bean
66
+    public Queue examBaseToPdfQueue() {
67
+        return new Queue(examBaseToPdfQueue);
68
+    }
54 69
     @Bean
55 70
     public Queue examBaseToScanImgQueue(){ return new Queue(examBaseToScanImgQueue);}
56 71
     @Bean
57
-    public Queue examBaseToScanImgHandleQueue(){ return new Queue(examBaseToScanImgHandleQueue);}
72
+    public Queue examImgToPdfQueue(){ return new Queue(examImgToPdfQueue);}
58 73
 
74
+    //负载二生产者mq
59 75
     @Bean
60
-    public Queue examImgToPdfQueue(){ return new Queue(examImgToPdfQueue);}
76
+    public Queue examImgMergeQueue2() {
77
+        return new Queue(examImgMergeQueue2);
78
+    }
61 79
     @Bean
62
-    public Queue examImgToPdfHandleQueue(){ return new Queue(examImgToPdfHandleQueue);}
80
+    public Queue examBaseToPdfQueue2() {
81
+        return new Queue(examBaseToPdfQueue2);
82
+    }
83
+    @Bean
84
+    public Queue examBaseToScanImgQueue2(){ return new Queue(examBaseToScanImgQueue2);}
85
+    @Bean
86
+    public Queue examImgToPdfQueue2(){ return new Queue(examImgToPdfQueue2);}
63 87
 }

+ 32
- 7
sexam/src/main/java/com/xhkjedu/sexam/listener/MessageSender.java 파일 보기

@@ -22,16 +22,26 @@ import java.util.Map;
22 22
 public class MessageSender {
23 23
     @Autowired
24 24
     private AmqpTemplate rabbitTemplate;
25
-
25
+    //负载一生产者mq
26 26
     @Value("${rabbitmq.examImgMergeQueue}")
27 27
     private String examImgMergeQueue;
28 28
     @Value("${rabbitmq.examBaseToPdfQueue}")
29 29
     private String examBaseToPdfQueue;
30 30
     @Value("${rabbitmq.examBaseToScanImgQueue}")
31 31
     private String examBaseToScanImgQueue;
32
-    private String examBaseToScanImgHandleQueue;
33 32
     @Value("${rabbitmq.examImgToPdfQueue}")
34 33
     private String examImgToPdfQueue;
34
+    //负载二生产者mq
35
+    @Value("${rabbitmq.examImgMergeQueue2}")
36
+    private String examImgMergeQueue2;
37
+    @Value("${rabbitmq.examBaseToPdfQueue2}")
38
+    private String examBaseToPdfQueue2;
39
+    @Value("${rabbitmq.examBaseToScanImgQueue2}")
40
+    private String examBaseToScanImgQueue2;
41
+    @Value("${rabbitmq.examImgToPdfQueue2}")
42
+    private String examImgToPdfQueue2;
43
+    //负载一节点名称
44
+    private final String node2="node02/";
35 45
 
36 46
     /**
37 47
      * @Description 学生答案合并
@@ -45,7 +55,11 @@ public class MessageSender {
45 55
         map.put("epsqid", epsqid);
46 56
         map.put("stuanswers", userAnswers);
47 57
         map.put("device", device);
48
-        rabbitTemplate.convertAndSend(examImgMergeQueue, JSON.toJSONString(map));
58
+        if (userAnswers.toString().contains(node2)) {
59
+            rabbitTemplate.convertAndSend(examImgMergeQueue2, JSON.toJSONString(map));
60
+        } else {
61
+            rabbitTemplate.convertAndSend(examImgMergeQueue, JSON.toJSONString(map));
62
+        }
49 63
     }
50 64
 
51 65
     /**
@@ -63,8 +77,11 @@ public class MessageSender {
63 77
         map.put("scantroncol", scantroncol);
64 78
         map.put("savefolder",savefolder);
65 79
         map.put("filename",filename);
66
-
67
-        rabbitTemplate.convertAndSend(examBaseToPdfQueue, JSON.toJSONString(map));
80
+        if (imgs.toString().contains(node2)) {
81
+            rabbitTemplate.convertAndSend(examBaseToPdfQueue2, JSON.toJSONString(map));
82
+        } else {
83
+            rabbitTemplate.convertAndSend(examBaseToPdfQueue, JSON.toJSONString(map));
84
+        }
68 85
     }
69 86
 
70 87
     /**
@@ -80,7 +97,11 @@ public class MessageSender {
80 97
         map.put("examid", examid);
81 98
         map.put("imgs", imgs);
82 99
         map.put("savefolder",savefolder);
83
-        rabbitTemplate.convertAndSend(examBaseToScanImgQueue, JSON.toJSONString(map));
100
+        if (imgs.toString().contains(node2)) {
101
+            rabbitTemplate.convertAndSend(examBaseToScanImgQueue2, JSON.toJSONString(map));
102
+        } else {
103
+            rabbitTemplate.convertAndSend(examBaseToScanImgQueue, JSON.toJSONString(map));
104
+        }
84 105
     }
85 106
 
86 107
     /**
@@ -94,6 +115,10 @@ public class MessageSender {
94 115
         Map map = new HashMap();
95 116
         map.put("epid",epid);
96 117
         map.put("imgs", imgs);
97
-        rabbitTemplate.convertAndSend(examImgToPdfQueue, JSON.toJSONString(map));
118
+        if (imgs.toString().contains(node2)) {
119
+            rabbitTemplate.convertAndSend(examImgToPdfQueue2, JSON.toJSONString(map));
120
+        } else {
121
+            rabbitTemplate.convertAndSend(examImgToPdfQueue, JSON.toJSONString(map));
122
+        }
98 123
     }
99 124
 }

+ 5
- 2
sexam/src/main/java/com/xhkjedu/sexam/mapper/paperstudent/EPaperStudentQuestionMapper.java 파일 보기

@@ -1,11 +1,9 @@
1 1
 package com.xhkjedu.sexam.mapper.paperstudent;
2 2
 
3 3
 import com.xhkjedu.sexam.base.TkMapper;
4
-import com.xhkjedu.sexam.model.paperstudent.EPaperStudent;
5 4
 import com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion;
6 5
 import com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo;
7 6
 import org.apache.ibatis.annotations.Param;
8
-import org.springframework.jmx.export.annotation.ManagedOperationParameter;
9 7
 import org.springframework.stereotype.Repository;
10 8
 
11 9
 import java.util.List;
@@ -61,4 +59,9 @@ public interface EPaperStudentQuestionMapper extends TkMapper<EPaperStudentQuest
61 59
     //根据学生试卷id获取学生作答内容
62 60
     List<EPaperStudentQuestion> listStuQuestionsByEpsid(@Param("epsid")Integer epsid);
63 61
 
62
+    //获取试卷中未合并图片
63
+    List<EPaperStudentQuestion> listNoMergeUserAnswer();
64
+
65
+    //获取未合并图片考试模式列表
66
+    List<Map> listExamByIds(@Param("examids") List<Integer> examids);
64 67
 }

+ 25
- 0
sexam/src/main/java/com/xhkjedu/sexam/service/paperstudent/EPaperStudentService.java 파일 보기

@@ -405,6 +405,31 @@ public class EPaperStudentService {
405 405
         }
406 406
     }
407 407
 
408
+    /*
409
+     * 合并学生答案
410
+     * @Param []
411
+     * @Author ywx
412
+     * @Date 2022/11/12 17:34
413
+     * @return void
414
+     **/
415
+    public void paperStuQuestionAnswerMerge() {
416
+        //获取试卷中未合并图片
417
+        List<EPaperStudentQuestion> list = ePaperStudentQuestionMapper.listNoMergeUserAnswer();
418
+        if (N_Utils.isListEmpty(list)) return;
419
+        List<Integer> examids = list.stream().map(s -> s.getExamid()).distinct().collect(Collectors.toList());
420
+        List<Map> exams = ePaperStudentQuestionMapper.listExamByIds(examids);//获取未合并图片考试模式列表
421
+        Map<Integer, Integer> emap = exams.stream().collect(Collectors.toMap(e -> (Integer) e.get("examid")
422
+                , e -> (Integer) e.get("exammode")));
423
+        if (N_Utils.isListNotEmpty(list)) {
424
+            for (EPaperStudentQuestion sq : list) {
425
+                List<String> stuanswer = JSON.parseArray(sq.getStuanswer(), String.class);
426
+                if (N_Utils.isListNotEmpty(stuanswer) && stuanswer.size() > 1) {
427
+                    convertUtil.imgMerge(sq.getEpsqid(), stuanswer, emap.get(sq.getExamid()));
428
+                }
429
+            }
430
+        }
431
+    }
432
+
408 433
     /**
409 434
      * @Description 提交试卷试题(网页端)
410 435
      * @Param [pswvo]

+ 16
- 0
sexam/src/main/java/com/xhkjedu/sexam/task/PaperTask.java 파일 보기

@@ -2,6 +2,7 @@ package com.xhkjedu.sexam.task;
2 2
 
3 3
 import com.xhkjedu.sexam.mapper.exam.ESubjectMapper;
4 4
 import com.xhkjedu.sexam.mapper.paper.EPaperCorrectTeacherMapper;
5
+import com.xhkjedu.sexam.service.paperstudent.EPaperStudentService;
5 6
 import lombok.extern.slf4j.Slf4j;
6 7
 import org.springframework.scheduling.annotation.Async;
7 8
 import org.springframework.scheduling.annotation.Scheduled;
@@ -23,6 +24,8 @@ public class PaperTask {
23 24
     private ESubjectMapper eSubjectMapper;
24 25
     @Resource
25 26
     private EPaperCorrectTeacherMapper ePaperCorrectTeacherMapper;
27
+    @Resource
28
+    EPaperStudentService ePaperStudentService;
26 29
 
27 30
     /**
28 31
      * 试卷开始考试
@@ -63,4 +66,17 @@ public class PaperTask {
63 66
         ePaperCorrectTeacherMapper.unLockQuestion();
64 67
     }
65 68
 
69
+    /*
70
+     * 合并学生答案
71
+     * @Param []
72
+     * @Author ywx
73
+     * @Date 2022/11/12 17:17
74
+     * @return void
75
+     **/
76
+    @Async("threadPoolTaskScheduler")
77
+    @Scheduled(cron = "${cron.imgMerge}")
78
+    public void paperStuQuestionAnswerMerge() {
79
+        ePaperStudentService.paperStuQuestionAnswerMerge();
80
+    }
81
+
66 82
 }

+ 13
- 4
sexam/src/main/resources/application.properties 파일 보기

@@ -51,14 +51,21 @@ spring.redis.jedis.pool.max-active=60000
51 51
 #缓存访问数据有效时长60*60*24*7
52 52
 redisdatatime=604800
53 53
 
54
-rabbitmq.examImgMergeQueue=xhkjedutest.xhschool.examImgMergeQueue_dev
54
+#消费者mq
55 55
 rabbitmq.examImgMergeHandleQueue=xhkjedutest.xhschool.examImgMergeHandleQueue_dev
56
-rabbitmq.examBaseToPdfQueue=xhkjedutest.xhschool.examBaseToPdfQueue_dev
57 56
 rabbitmq.examBaseToPdfHandleQueue=xhkjedutest.xhschool.examBaseToPdfHandleQueue_dev
58
-rabbitmq.examBaseToScanImgQueue=xhkjedutest.xhschool.examBaseToScanImgQueue_dev
59 57
 rabbitmq.examBaseToScanImgHandleQueue=xhkjedutest.xhschool.examBaseToScanImgHandleQueue_dev
60
-rabbitmq.examImgToPdfQueue=xhkjedutest.xhschool.examImgToPdfQueue_dev
61 58
 rabbitmq.examImgToPdfHandleQueue=xhkjedutest.xhschool.examImgToPdfHandleQueue_dev
59
+#负载一生产者mq
60
+rabbitmq.examImgMergeQueue=xhkjedutest.xhschool.examImgMergeQueue_node01_dev
61
+rabbitmq.examBaseToPdfQueue=xhkjedutest.xhschool.examBaseToPdfQueue_node01_dev
62
+rabbitmq.examBaseToScanImgQueue=xhkjedutest.xhschool.examBaseToScanImgQueue_node01_dev
63
+rabbitmq.examImgToPdfQueue=xhkjedutest.xhschool.examImgToPdfQueue_node01_dev
64
+#负载二生产者mq
65
+rabbitmq.examImgMergeQueue2=xhkjedutest.xhschool.examImgMergeQueue_node02_dev
66
+rabbitmq.examBaseToPdfQueue2=xhkjedutest.xhschool.examBaseToPdfQueue_node02_dev
67
+rabbitmq.examBaseToScanImgQueue2=xhkjedutest.xhschool.examBaseToScanImgQueue_node02_dev
68
+rabbitmq.examImgToPdfQueue2=xhkjedutest.xhschool.examImgToPdfQueue_node02_dev
62 69
 
63 70
 spring.rabbitmq.host=49.4.26.249
64 71
 spring.rabbitmq.port=5672
@@ -87,6 +94,8 @@ signName=【河南星火燎原】
87 94
 enable.scheduled=false
88 95
 #每隔1分钟修改试卷状态
89 96
 cron.updatePaperState=0 0/1 * * * ?
97
+#每天凌晨1点处理未合并的学生答案
98
+cron.imgMerge=0 0 1 * * ?
90 99
 
91 100
 #配置socket地址和face地址
92 101
 exam.socket=wss://wsexam.xhkjedu.com/ws

+ 12
- 0
sexam/src/main/resources/mapper/paperstudent/EPaperStudentQuestionMapper.xml 파일 보기

@@ -33,6 +33,18 @@
33 33
         select epsqid,stuanswer from e_paper_student_question
34 34
         where epsid=#{epsid} and answertype=1 and answered=1 and converted=0 order by qorder
35 35
     </select>
36
+    <!--获取试卷中未合并图片-->
37
+    <select id="listNoMergeUserAnswer" resultType="com.xhkjedu.sexam.model.paperstudent.EPaperStudentQuestion">
38
+        select epsqid,stuanswer,examid from e_paper_student_question
39
+        where answertype=1 and answered=1 and converted=0 order by qorder
40
+    </select>
41
+    <!--获取未合并图片考试模式列表-->
42
+    <select id="listExamByIds" resultType="java.util.Map">
43
+        select examid,exammode from e_base where examid in
44
+        <foreach collection="examids" item="examid" open="(" separator="," close=")">
45
+            ${examid}
46
+        </foreach>
47
+    </select>
36 48
 
37 49
     <!--获取试卷中所有试题正确答案及分值-->
38 50
     <select id="listPaperQuestionsAnswer" resultType="com.xhkjedu.sexam.vo.paperstudent.PsqAnswerVo">

+ 48
- 15
sstudy/src/main/java/com/xhkjedu/sstudy/config/RabbitConfig.java 파일 보기

@@ -13,7 +13,13 @@ import org.springframework.context.annotation.Configuration;
13 13
  **/
14 14
 @Configuration
15 15
 public class RabbitConfig {
16
+    //消费者mq
17
+    @Value("${rabbitmq.resourceHandleQueue}")
18
+    private String resourceHandleQueue;
19
+    @Value("${rabbitmq.imgMergeHandleQueue}")
20
+    private String imgMergeHandleQueue;
16 21
 
22
+    //负载一生产者mq
17 23
     @Value("${rabbitmq.resourceToPdfQueue}")
18 24
     private String resourceToPdfQueue;
19 25
     @Value("${rabbitmq.resourceTransferQueue}")
@@ -22,45 +28,72 @@ public class RabbitConfig {
22 28
     private String resourceUnZipQueue;
23 29
     @Value("${rabbitmq.resourceDelQueue}")
24 30
     private String resourceDelQueue;
25
-    @Value("${rabbitmq.resourceHandleQueue}")
26
-    private String resourceHandleQueue;
27 31
     @Value("${rabbitmq.imgMergeQueue}")
28 32
     private String imgMergeQueue;
29
-    @Value("${rabbitmq.imgMergeHandleQueue}")
30
-    private String imgMergeHandleQueue;
31 33
 
34
+    //负载二生产者mq
35
+    @Value("${rabbitmq.resourceToPdfQueue2}")
36
+    private String resourceToPdfQueue2;
37
+    @Value("${rabbitmq.resourceTransferQueue2}")
38
+    private String resourceTransferQueue2;
39
+    @Value("${rabbitmq.resourceUnZipQueue2}")
40
+    private String resourceUnZipQueue2;
41
+    @Value("${rabbitmq.resourceDelQueue2}")
42
+    private String resourceDelQueue2;
43
+    @Value("${rabbitmq.imgMergeQueue2}")
44
+    private String imgMergeQueue2;
45
+
46
+    //消费者mq
47
+    @Bean
48
+    public Queue resourceHandleQueue() {
49
+        return new Queue(resourceHandleQueue);
50
+    }
51
+    @Bean
52
+    public Queue imgMergeHandleQueue() {
53
+        return new Queue(imgMergeHandleQueue);
54
+    }
55
+
56
+    //负载一生产者mq
32 57
     @Bean
33 58
     public Queue resourceToPdfQueue() {
34 59
         return new Queue(resourceToPdfQueue);
35 60
     }
36
-
37 61
     @Bean
38 62
     public Queue resourceTransferQueue() {
39 63
         return new Queue(resourceTransferQueue);
40 64
     }
41
-
42 65
     @Bean
43 66
     public Queue resourceUnZipQueue() {
44 67
         return new Queue(resourceUnZipQueue);
45 68
     }
46
-
47 69
     @Bean
48 70
     public Queue resourceDelQueue() {
49 71
         return new Queue(resourceDelQueue);
50 72
     }
51
-
52
-    @Bean
53
-    public Queue resourceHandleQueue() {
54
-        return new Queue(resourceHandleQueue);
55
-    }
56
-
57 73
     @Bean
58 74
     public Queue imgMergeQueue() {
59 75
         return new Queue(imgMergeQueue);
60 76
     }
61 77
 
78
+    //负载二生产者mq
62 79
     @Bean
63
-    public Queue imgMergeHandleQueue() {
64
-        return new Queue(imgMergeHandleQueue);
80
+    public Queue resourceToPdfQueue2() {
81
+        return new Queue(resourceToPdfQueue2);
82
+    }
83
+    @Bean
84
+    public Queue resourceTransferQueue2() {
85
+        return new Queue(resourceTransferQueue2);
86
+    }
87
+    @Bean
88
+    public Queue resourceUnZipQueue2() {
89
+        return new Queue(resourceUnZipQueue2);
90
+    }
91
+    @Bean
92
+    public Queue resourceDelQueue2() {
93
+        return new Queue(resourceDelQueue2);
94
+    }
95
+    @Bean
96
+    public Queue imgMergeQueue2() {
97
+        return new Queue(imgMergeQueue2);
65 98
     }
66 99
 }

+ 46
- 7
sstudy/src/main/java/com/xhkjedu/sstudy/listener/MessageSender.java 파일 보기

@@ -21,6 +21,7 @@ import java.util.Map;
21 21
 public class MessageSender {
22 22
     @Autowired
23 23
     private AmqpTemplate rabbitTemplate;
24
+    //负载一生产者mq
24 25
     @Value("${rabbitmq.resourceToPdfQueue}")
25 26
     private String resourceToPdfQueue;
26 27
     @Value("${rabbitmq.resourceTransferQueue}")
@@ -31,23 +32,49 @@ public class MessageSender {
31 32
     private String resourceDelQueue;
32 33
     @Value("${rabbitmq.imgMergeQueue}")
33 34
     private String imgMergeQueue;
35
+    //负载二生产者mq
36
+    @Value("${rabbitmq.resourceToPdfQueue2}")
37
+    private String resourceToPdfQueue2;
38
+    @Value("${rabbitmq.resourceTransferQueue2}")
39
+    private String resourceTransferQueue2;
40
+    @Value("${rabbitmq.resourceUnZipQueue2}")
41
+    private String resourceUnZipQueue2;
42
+    @Value("${rabbitmq.resourceDelQueue2}")
43
+    private String resourceDelQueue2;
44
+    @Value("${rabbitmq.imgMergeQueue2}")
45
+    private String imgMergeQueue2;
46
+    //负载一节点名称
47
+    private final String node2="node02/";
34 48
 
35 49
     //资源转换mq
36 50
     public String convertResource(ResourceVo resource) {
37 51
         Integer resourceclass = resource.getResourceclass();
52
+        String resourceurl = resource.getResourceurl();
38 53
         Map map = new HashMap();
39 54
         map.put("resourceid", resource.getResourceid());
40 55
         map.put("resourceclass", resourceclass);
41
-        map.put("resourceurl", resource.getResourceurl());
56
+        map.put("resourceurl", resourceurl);
42 57
         map.put("suffix", resource.getSuffix());
43 58
         String mqKey;
44 59
         if (resourceclass == 5) {
45 60
             map.put("source", "resource");
46
-            mqKey = resourceTransferQueue;
61
+            if (resourceurl.contains(node2)) {
62
+                mqKey = resourceTransferQueue2;
63
+            } else {
64
+                mqKey = resourceTransferQueue;
65
+            }
47 66
         } else if (resourceclass == 7) {
48
-            mqKey = resourceUnZipQueue;
67
+            if (resourceurl.contains(node2)) {
68
+                mqKey = resourceUnZipQueue2;
69
+            } else {
70
+                mqKey = resourceUnZipQueue;
71
+            }
49 72
         } else {
50
-            mqKey = resourceToPdfQueue;
73
+            if (resourceurl.contains(node2)) {
74
+                mqKey = resourceToPdfQueue2;
75
+            } else {
76
+                mqKey = resourceToPdfQueue;
77
+            }
51 78
         }
52 79
         rabbitTemplate.convertAndSend(mqKey, JSON.toJSONString(map));
53 80
         return null;
@@ -61,12 +88,20 @@ public class MessageSender {
61 88
         map.put("resourceurl", resourceurl);
62 89
         map.put("suffix", "mp4");
63 90
         map.put("source", source);
64
-        rabbitTemplate.convertAndSend(resourceTransferQueue, JSON.toJSONString(map));
91
+        if (resourceurl.contains(node2)) {
92
+            rabbitTemplate.convertAndSend(resourceTransferQueue2, JSON.toJSONString(map));
93
+        } else {
94
+            rabbitTemplate.convertAndSend(resourceTransferQueue, JSON.toJSONString(map));
95
+        }
65 96
     }
66 97
 
67 98
     //资源删除mq
68 99
     public void resourceDel(List<String> resourceurls) {
69
-        rabbitTemplate.convertAndSend(resourceDelQueue, JSON.toJSONString(resourceurls));
100
+        if (resourceurls.toString().contains(node2)) {
101
+            rabbitTemplate.convertAndSend(resourceDelQueue2, JSON.toJSONString(resourceurls));
102
+        } else {
103
+            rabbitTemplate.convertAndSend(resourceDelQueue, JSON.toJSONString(resourceurls));
104
+        }
70 105
     }
71 106
 
72 107
     /**
@@ -82,6 +117,10 @@ public class MessageSender {
82 117
         map.put("psqid", psqid);
83 118
         map.put("userAnswers", userAnswers);
84 119
         map.put("papertype", papertype);
85
-        rabbitTemplate.convertAndSend(imgMergeQueue, JSON.toJSONString(map));
120
+        if (userAnswers.toString().contains(node2)) {
121
+            rabbitTemplate.convertAndSend(imgMergeQueue2, JSON.toJSONString(map));
122
+        } else {
123
+            rabbitTemplate.convertAndSend(imgMergeQueue, JSON.toJSONString(map));
124
+        }
86 125
     }
87 126
 }

+ 13
- 6
sstudy/src/main/resources/application.properties 파일 보기

@@ -56,14 +56,21 @@ spring.redis.jedis.pool.max-active=60000
56 56
 redisdatatime=604800
57 57
 #secretKey必须为24位
58 58
 secretKey=nanhuakaizhangjianwangni
59
-
60
-rabbitmq.resourceToPdfQueue=xhkjedutest.xhschool.resourceToPdfQueue_dev
61
-rabbitmq.resourceTransferQueue=xhkjedutest.xhschool.resourceTransferQueue_dev
62
-rabbitmq.resourceUnZipQueue=xhkjedutest.xhschool.resourceUnZipQueue_dev
63
-rabbitmq.resourceDelQueue=xhkjedutest.xhschool.resourceDelQueue_dev
59
+#消费者mq
64 60
 rabbitmq.resourceHandleQueue=xhkjedutest.xhschool.resourceHandleQueue_dev
65
-rabbitmq.imgMergeQueue=xhkjedutest.xhschool.imgMergeQueue_dev
66 61
 rabbitmq.imgMergeHandleQueue=xhkjedutest.xhschool.imgMergeHandleQueue_dev
62
+#负载一生产者mq
63
+rabbitmq.resourceToPdfQueue=xhkjedutest.xhschool.resourceToPdfQueue_node01_dev
64
+rabbitmq.resourceTransferQueue=xhkjedutest.xhschool.resourceTransferQueue_node01_dev
65
+rabbitmq.resourceUnZipQueue=xhkjedutest.xhschool.resourceUnZipQueue_node01_dev
66
+rabbitmq.resourceDelQueue=xhkjedutest.xhschool.resourceDelQueue_node01_dev
67
+rabbitmq.imgMergeQueue=xhkjedutest.xhschool.imgMergeQueue_node01_dev
68
+#负载二生产者mq
69
+rabbitmq.resourceToPdfQueue2=xhkjedutest.xhschool.resourceToPdfQueue_node02_dev
70
+rabbitmq.resourceTransferQueue2=xhkjedutest.xhschool.resourceTransferQueue_node02_dev
71
+rabbitmq.resourceUnZipQueue2=xhkjedutest.xhschool.resourceUnZipQueue_node02_dev
72
+rabbitmq.resourceDelQueue2=xhkjedutest.xhschool.resourceDelQueue_node02_dev
73
+rabbitmq.imgMergeQueue2=xhkjedutest.xhschool.imgMergeQueue_node02_dev
67 74
 spring.rabbitmq.host=49.4.26.249
68 75
 spring.rabbitmq.port=5672
69 76
 spring.rabbitmq.username=xhkjedu

Loading…
취소
저장