123
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
package com.ruoyi.test.business;
|
package com.ruoyi.test.business;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.ruoyi.cai.trd.Agora;
|
import com.ruoyi.cai.trd.Agora;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class AgoreTest {
|
public class AgoreTest {
|
||||||
@@ -15,8 +18,12 @@ public class AgoreTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void closeChannel(){
|
public void closeChannel(){
|
||||||
Long roomId = 1779785009948024833L;
|
Long roomId = 1779868994539642881L;
|
||||||
|
// List<String> channelUsers = agora.getChannelUsers(roomId);
|
||||||
|
// System.out.println(JSON.toJSONString(channelUsers));
|
||||||
agora.closeChannel(roomId);
|
agora.closeChannel(roomId);
|
||||||
|
// agora.closeChannelByUser(roomId,2644L);
|
||||||
|
// agora.closeChannelByUser(roomId,3324L);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ import java.util.concurrent.*;
|
|||||||
*/
|
*/
|
||||||
public class ExecutorConstant {
|
public class ExecutorConstant {
|
||||||
|
|
||||||
private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
// private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
||||||
|
private final static int CPU_NUM = 6;
|
||||||
|
|
||||||
public static Executor SYNC_EXECUTOR;
|
public static Executor SYNC_EXECUTOR;
|
||||||
|
|
||||||
@@ -48,6 +49,10 @@ public class ExecutorConstant {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(6 << 2);
|
||||||
|
}
|
||||||
|
|
||||||
private static ThreadFactory init(String nameFormat){
|
private static ThreadFactory init(String nameFormat){
|
||||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
public class RabbitMqConfig {
|
public class RabbitMqConfig {
|
||||||
|
|
||||||
//并发数量
|
//并发数量
|
||||||
public static final int DEFAULT_CONCURRENT = Runtime.getRuntime().availableProcessors();
|
// public static final int DEFAULT_CONCURRENT = Runtime.getRuntime().availableProcessors();
|
||||||
|
public static final int DEFAULT_CONCURRENT = 6;
|
||||||
|
|
||||||
@Bean("customContainerFactory")
|
@Bean("customContainerFactory")
|
||||||
public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
|
public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
|
||||||
ConnectionFactory connectionFactory) {
|
ConnectionFactory connectionFactory) {
|
||||||
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
|
||||||
factory.setConcurrentConsumers(DEFAULT_CONCURRENT*2);
|
factory.setConcurrentConsumers(DEFAULT_CONCURRENT);
|
||||||
factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT*2);
|
factory.setMaxConcurrentConsumers(DEFAULT_CONCURRENT*2);
|
||||||
configurer.configure(factory, connectionFactory);
|
configurer.configure(factory, connectionFactory);
|
||||||
return factory;
|
return factory;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpMethod;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@@ -35,8 +36,8 @@ public class Agora {
|
|||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.set("Authorization", getAuthorizationHeader());
|
headers.set("Authorization", getAuthorizationHeader());
|
||||||
HttpEntity httpEntity = new HttpEntity<>(headers);
|
HttpEntity request = new HttpEntity<>(headers);
|
||||||
JSONObject jsonobject = RestTemplateUtil.restTemplate.getForObject(url,JSONObject.class,httpEntity);
|
JSONObject jsonobject = RestTemplateUtil.restTemplate.exchange(url, HttpMethod.GET, request, JSONObject.class).getBody();
|
||||||
// "success":true,"data":{"channel_exist":true,"mode":2,"broadcasters":[1001,1025],"audience":[],"audience_total":0}}
|
// "success":true,"data":{"channel_exist":true,"mode":2,"broadcasters":[1001,1025],"audience":[],"audience_total":0}}
|
||||||
if(jsonobject == null){
|
if(jsonobject == null){
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
@@ -45,8 +46,25 @@ public class Agora {
|
|||||||
return jsonArray.toJavaList(String.class);
|
return jsonArray.toJavaList(String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void closeChannelByUser(Long roomId,Long uid){
|
||||||
|
String url = "https://api.sd-rtn.com/dev/v1/kicking-rule";
|
||||||
|
Map<String,Object> bodyData = new HashMap<>();
|
||||||
|
bodyData.put("appid",agoraProperties.getAppId());
|
||||||
|
bodyData.put("cname",roomId);
|
||||||
|
bodyData.put("uid",uid);
|
||||||
|
bodyData.put("time",0);
|
||||||
|
bodyData.put("privileges", Collections.singletonList("join_channel"));
|
||||||
|
HttpHeaders headers = new HttpHeaders();
|
||||||
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
|
headers.set("Authorization", getAuthorizationHeader());
|
||||||
|
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
||||||
|
JSONObject jsonObject = RestTemplateUtil.restTemplate.exchange(url,HttpMethod.POST, httpEntity, JSONObject.class).getBody();
|
||||||
|
log.info("执行关闭房间号操作:roomId={},response={}",roomId, JSON.toJSONString(jsonObject));
|
||||||
|
}
|
||||||
|
|
||||||
public void closeChannel(Long roomId){
|
public void closeChannel(Long roomId){
|
||||||
String url = "http://api.sd-rtn.com/dev/v1/kicking-rule";
|
String url = "https://api.sd-rtn.com/dev/v1/kicking-rule";
|
||||||
Map<String,Object> bodyData = new HashMap<>();
|
Map<String,Object> bodyData = new HashMap<>();
|
||||||
bodyData.put("appid",agoraProperties.getAppId());
|
bodyData.put("appid",agoraProperties.getAppId());
|
||||||
bodyData.put("cname",roomId);
|
bodyData.put("cname",roomId);
|
||||||
@@ -56,7 +74,7 @@ public class Agora {
|
|||||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||||
headers.set("Authorization", getAuthorizationHeader());
|
headers.set("Authorization", getAuthorizationHeader());
|
||||||
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
HttpEntity httpEntity = new HttpEntity<>(bodyData, headers);
|
||||||
JSONObject jsonObject = RestTemplateUtil.restTemplate.postForObject(url, httpEntity, JSONObject.class);
|
JSONObject jsonObject = RestTemplateUtil.restTemplate.exchange(url,HttpMethod.POST, httpEntity, JSONObject.class).getBody();
|
||||||
log.info("执行关闭房间号操作:roomId={},response={}",roomId, JSON.toJSONString(jsonObject));
|
log.info("执行关闭房间号操作:roomId={},response={}",roomId, JSON.toJSONString(jsonObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ public class ThreadPoolConfig {
|
|||||||
/**
|
/**
|
||||||
* 核心线程数 = cpu 核心数 + 1
|
* 核心线程数 = cpu 核心数 + 1
|
||||||
*/
|
*/
|
||||||
private final int core = Runtime.getRuntime().availableProcessors() + 1;
|
// private final int core = Runtime.getRuntime().availableProcessors() + 1;
|
||||||
|
private final int core = 6 + 1;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ThreadPoolProperties threadPoolProperties;
|
private ThreadPoolProperties threadPoolProperties;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.controller;
|
package com.ruoyi.controller;
|
||||||
|
|
||||||
import cn.dev33.satoken.annotation.SaIgnore;
|
import cn.dev33.satoken.annotation.SaIgnore;
|
||||||
|
import com.ruoyi.cai.ws.holder.WebSocketSessionHolder;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import java.util.concurrent.*;
|
|||||||
*/
|
*/
|
||||||
public class YunExecutor {
|
public class YunExecutor {
|
||||||
|
|
||||||
private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
// private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
||||||
|
|
||||||
|
private final static int CPU_NUM = 5;
|
||||||
|
|
||||||
public static Executor YUN_EXECUTOR;
|
public static Executor YUN_EXECUTOR;
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.ruoyi.yunxin.config;
|
|
||||||
|
|
||||||
import com.alibaba.ttl.threadpool.TtlExecutors;
|
|
||||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
||||||
|
|
||||||
import java.util.concurrent.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 线程变量定义
|
|
||||||
* <p>created on 2023/3/3 11:16</p>
|
|
||||||
* @author ZL
|
|
||||||
*/
|
|
||||||
public class YunxinExecutorConstant {
|
|
||||||
|
|
||||||
private final static int CPU_NUM = Runtime.getRuntime().availableProcessors();
|
|
||||||
public static Executor COMMON_EXECUTOR;
|
|
||||||
|
|
||||||
static {
|
|
||||||
ThreadPoolExecutor commonExecutor = new ThreadPoolExecutor(CPU_NUM,
|
|
||||||
CPU_NUM << 2,
|
|
||||||
5,
|
|
||||||
TimeUnit.SECONDS,
|
|
||||||
new ArrayBlockingQueue<>(50),
|
|
||||||
init("commonThreadPool-%d"),
|
|
||||||
new ThreadPoolExecutor.CallerRunsPolicy());
|
|
||||||
COMMON_EXECUTOR = TtlExecutors.getTtlExecutor(commonExecutor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ThreadFactory init(String nameFormat){
|
|
||||||
return new ThreadFactoryBuilder().setNameFormat(nameFormat).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ThreadPoolExecutor initExecutor(int corePoolSize, int maxPoolSize, int keepAliveTime, TimeUnit timeUnit,
|
|
||||||
BlockingQueue<Runnable> workQueue, String nameFormat){
|
|
||||||
return new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, timeUnit, workQueue,
|
|
||||||
init(nameFormat));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user