init
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ruoyi.yunxin;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.ruoyi.yunxin.client.ImMessageClient;
|
||||
import com.ruoyi.yunxin.config.YunxinExecutorConstant;
|
||||
import com.ruoyi.yunxin.config.YunxinProperties;
|
||||
import com.ruoyi.yunxin.req.Option;
|
||||
import com.ruoyi.yunxin.req.SendAttachMsgReq;
|
||||
@@ -26,6 +27,12 @@ public class Yunxin {
|
||||
@Resource
|
||||
private ImMessageClient messageClient;
|
||||
|
||||
public void sendToSync(Long toUid,Long fromUid,Object data){
|
||||
YunxinExecutorConstant.COMMON_EXECUTOR.execute(() -> {
|
||||
this.sendTo(toUid,fromUid,data);
|
||||
});
|
||||
}
|
||||
|
||||
public YxDataR<SendMsgResp> sendTo(Long toUid,Long fromUid,Object data){
|
||||
SendMsgReq req = new SendMsgReq();
|
||||
req.setFrom(fromUid == null ? yunxinProperties.getDefaultFromUid() : fromUid+"");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
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