parent
6878457f44
commit
a4fb4bef4f
@ -0,0 +1,107 @@
|
||||
package com.ruoyi.flyingbook.consumer;
|
||||
|
||||
import cn.hutool.core.thread.ThreadFactoryBuilder;
|
||||
import com.ruoyi.common.constant.RedisConstants;
|
||||
import com.ruoyi.common.enums.EventOperateStatus;
|
||||
import com.ruoyi.flyingbook.domain.Event;
|
||||
import com.ruoyi.flyingbook.mapper.EventMapper;
|
||||
import com.ruoyi.flyingbook.service.IEventService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionException;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author yuxiangyong
|
||||
* @create 2023-03-12 23:04
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LarkApplicationRunner implements ApplicationRunner {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 核心线程数
|
||||
*/
|
||||
private static final Integer CORE_POOL_SIZE = 1;
|
||||
/**
|
||||
* 最大线程数
|
||||
*/
|
||||
private static final Integer MAX_POOL_SIZE = 1;
|
||||
/**
|
||||
* 存活时间
|
||||
*/
|
||||
private static final Integer KEEP_ALIVE_TIME = 30;
|
||||
|
||||
/**
|
||||
* 队列长度
|
||||
*/
|
||||
private static final Integer QUEUE_SIZE = 20;
|
||||
/**
|
||||
* 线程睡眠时间
|
||||
*/
|
||||
private static final Integer WAIT_TIME = 5000;
|
||||
|
||||
@Autowired
|
||||
private EventMapper eventMapper;
|
||||
|
||||
ThreadPoolExecutor threadPool = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(QUEUE_SIZE), new ThreadPoolExecutor.AbortPolicy());
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
//这里用线程池,后续如果出现量大的情况下可以调整
|
||||
// threadPool.execute(() -> {
|
||||
//
|
||||
// while (true) {
|
||||
// List<String> statusList = Arrays.asList(EventOperateStatus.PENDING.getCode(),EventOperateStatus.FAIL.getCode());
|
||||
// List<Event> eventList = eventMapper.queryListOperate(statusList);
|
||||
// if (CollectionUtils.isEmpty(eventList)) {
|
||||
// try {
|
||||
// // 没有订单,休息一下
|
||||
// Thread.sleep(WAIT_TIME);
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// } else {
|
||||
// try {
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private void operate(Event event){
|
||||
if (StringUtils.isNotBlank(event.getMessage())){
|
||||
queryAndOperate(event);
|
||||
}else {
|
||||
executeOperate(event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void queryAndOperate(Event event){
|
||||
|
||||
}
|
||||
|
||||
private void executeOperate(Event event){
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in new issue