The new Java project studies online notes -day14 (V)

1.3 video processing to send a message 
when the video upload process successfully sent video messages to MQ. Modify media asset management services to upload file code when the file upload successfully sent to the video processing MQ messages. 1.3.1 RabbitMQ configuration 
1, the configuration RabbitmqCon fi g in media-processor-based engineering project copied to media.
2, the configuration information modifying application.yml mq queues in media engineering
 

[AppleScript]  plain text view  Copy the code

?

1

2

3

4

xc‐service‐manage‐media:

  mq:  

  queue‐media‐video‐processor: queue_media_video_processor 

   routingkey‐media‐video: routingkey_media_video


1.3.2 Modify Service 
add code to handle video message transmitted to the document merger process mq:
 

[AppleScript]  plain text view  Copy the code

?

01

02

03

04

05

06

07

08

09

10

11

12

13

14

15

16

17

18

19

20

21

//向MQ发送视频处理消息 

   public ResponseResult sendProcessVideoMsg(String mediaId){    

   Optional<MediaFile> optional = mediaFileRepository.findById(fileMd5)

       if(!optional.isPresent()){   

       return new ResponseResult(CommonCode.FAIL);   

     }    

   MediaFile mediaFile = optional.get();   

     //发送视频处理消息    

    Map<String,String> msgMap = new HashMap<>();   

     msgMap.put("mediaId",mediaId);    

    //发送的消息      

  String msg = JSON.toJSONString(msgMap);    

    try {         

    this.rabbitTemplate.convertAndSend(RabbitMQConfig.EX_MEDIA_PROCESSTASK,routingkey_media_video,  msg);             LOGGER.info("send media process task msg:{}",msg)

       }catch (Exception e){    

        e.printStackTrace();    

        LOGGER.info("send media process task error,msg is:{},error:{}",msg,e.getMessage());     

       return new ResponseResult(CommonCode.FAIL);  

      }    

    return new ResponseResult(CommonCode.SUCCESS);  

    }


In mergechunks last method invoked sendProcessVideo method.
 

[AppleScript]  plain text view  Copy the code

?

1

2

3

4

5

6

7

...... 

       //状态为上传成功  

      mediaFile.setFileStatus("301002");    

    mediaFileRepository.save(mediaFile);  

      String mediaId = mediaFile.getFileId();   

     //向MQ发送视频处理消息  

      sendProcessVideoMsg(mediaId); ......


1.4 Video Test 
Test procedure:
1, upload avi file
2, to observe whether the log transmitting Message 3, observe the video processing process whether the received message is processed
4 was observed mp4 file is generated 5, to observe whether m3u8 and ts file generation 1.5 Video Processing the concurrency 
code used to specify annotation @RabbitListener consumption method, single-threaded default listen queue, the queue can be observed when a plurality of tasks each end consumer spending only a message, the message processing threaded prone to slow message processing, message accumulation not the greatest use of hardware resources.
Mq plant container can be configured parameters, increasing the number of concurrent processing can be realized listen queue multithreading, multi-thread processing message.
1, arranged in the plant container add RabbitmqCon fi g.java:
 

[AppleScript]  plain text view  Copy the code

?

1

2

3

4

5

6

7

8

9

//消费者并发数量 public static final int DEFAULT_CONCURRENT = 10

 @Bean("customContainerFactory") public SimpleRabbitListenerContainerFactory

  containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer, ConnectionFactory

 connectionFactory) {   

 SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();

    factory.setConcurrentConsumers(DEFAULT_CONCURRENT);   

 factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT)

   configurer.configure(factory, connectionFactory);  

  return factory; }


2, the container specified in the annotation facility @RabbitListener
 

[AppleScript]  plain text view  Copy the code

?

1

2

3

//视频处理方法

 @RabbitListener(queues = {"${xc‐service‐manage‐media.mq.queue‐media‐video‐processor}"},      

          containerFactory="customContainerFactory")


The test again when there is more than one task queue consumer side of concurrent processing capability

Guess you like

Origin blog.csdn.net/czbkzmj/article/details/91802886