幸运24-雪花主键-mq-合并topic
This commit is contained in:
@@ -3,26 +3,21 @@ package com.accompany.scheduler.task.luckyBag;
|
||||
import com.accompany.business.message.Lucky24Message;
|
||||
import com.accompany.business.service.gift.Lucky24MessageService;
|
||||
import com.accompany.business.service.lucky.Lucky24RecordService;
|
||||
import com.accompany.common.redis.RedisKey;
|
||||
import com.accompany.common.utils.DateTimeUtil;
|
||||
import com.accompany.core.model.PartitionInfo;
|
||||
import com.accompany.core.service.common.JedisService;
|
||||
import com.accompany.core.service.partition.PartitionInfoService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.Duration;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -32,40 +27,9 @@ public class Lucky24Task {
|
||||
private PartitionInfoService partitionInfoService;
|
||||
@Autowired
|
||||
private Lucky24RecordService service;
|
||||
|
||||
@Autowired
|
||||
private JedisService jedisService;
|
||||
@Autowired
|
||||
private Lucky24MessageService lucky24MessageService;
|
||||
|
||||
/**
|
||||
* 重新消费队列的消息
|
||||
*/
|
||||
@Scheduled(cron = "0 */5 * * * ?")
|
||||
public void retryLucky24Queue() {
|
||||
log.info("retryLucky24Queue start ...");
|
||||
Map<String, String> map = jedisService.hgetAll(RedisKey.lucky_24_status.getKey());
|
||||
if (map == null || map.size() == 0) {
|
||||
return;
|
||||
}
|
||||
long curTime = System.currentTimeMillis();
|
||||
long gapTime = 1000 * 60 * 10; // 十分钟内没被消费
|
||||
|
||||
map.entrySet().parallelStream().forEach(entry -> {
|
||||
try {
|
||||
String messId = entry.getKey();
|
||||
String val = entry.getValue();
|
||||
Lucky24Message giftMessage = JSON.parseObject(val, Lucky24Message.class);
|
||||
if (curTime - giftMessage.getCreateTime() > gapTime) {
|
||||
lucky24MessageService.handleMessage(giftMessage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("retryLucky24Queue error", e);
|
||||
}
|
||||
});
|
||||
log.info("retryLucky24Queue end ...");
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新消费队列的消息
|
||||
*/
|
||||
@@ -84,7 +48,7 @@ public class Lucky24Task {
|
||||
String messId = entry.getKey();
|
||||
Lucky24Message giftMessage = entry.getValue();
|
||||
if (curTime - giftMessage.getCreateTime() > gapTime) {
|
||||
lucky24MessageService.handleMessageV2(giftMessage);
|
||||
lucky24MessageService.handleMessage(giftMessage);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("retryLucky24Queue error", e);
|
||||
|
Reference in New Issue
Block a user