Intro
用戶提交 YouTube 視頻 URL 後,系統立即將請求分發至消息隊列(Queue)進行異步處理,並迅速返回響應以通知請求已接收。
異步處理過程包括下載視頻文件以及執行 MP3/MP4 格式的轉換任務。轉換完成後,處理結果(如文件名稱或嵌入地址)被推送到相應的消息隊列。前端通過訂閱的隊列接收處理完成的通知,根據返回的資訊更新 UI,顯示下載按鈕,供用戶點擊下載轉換完成的文件
sample
[用戶端]
-- WebSocket
-- [Nginx]
--代理請求
--> [Spring Boot]
-- 消費消息
--> [RabbitMQ]
-- 推送消息(/topic/convert,/topic/embedUrl)
--> [用戶端]
backend
server:
port: 64102
spring:
application:
name: YT1-service
cloud:
nacos:
discovery:
autoRegister: true # Nacos服务自动注册
server-addr: 192.168.33.11:8848
group: DEFAULT_GROUP_YT1
config:
server-addr: 192.168.33.11:8848
file-extension: yml
group: DEFAULT_GROUP_YT1
启用异步支持 在 Spring 配置类中添加 @EnableAsync 注解
package com.feddoubt.common.YT1.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@Configuration
@EnableAsync//启用异步支持 在 Spring 配置类中添加 @EnableAsync 注解
public class AsyncConfig {
@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setThreadNamePrefix("AsyncTask-");
executor.setCorePoolSize(10);
executor.setMaxPoolSize(20);
executor.setQueueCapacity(100);
executor.initialize();
return executor;
}
}