作者 朱兆平

雪花算法生成方法时间超长40s左右问题修复.增加路由订阅者日志展示

... ... @@ -6,6 +6,7 @@ import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService;
import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -14,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Service
public class MessageRouterReciverImpl implements MessageRouterReciverService {
... ... @@ -43,11 +45,13 @@ public class MessageRouterReciverImpl implements MessageRouterReciverService {
) {
if (StringUtils.isNotBlank(rcvr.getRcvrTopic())){
rcvr.setMessageRouterId(messageRouter.getId());
rcvr.setId(IdUtils.generateId());
List<MessageRouterReciver> list = messageRouterReciverMapper.selectByRouterKeyAndTopic(rcvr);
//判断是否已经有这条数据
if(list.isEmpty()){
rcvr.setId(IdUtils.generateId());
i += messageRouterReciverMapper.insertSelective(rcvr);
log.info("新增{}的类型{}订阅者{}成功,关联订阅者ID{}",messageRouter.getSndr(),messageRouter.getStype(),rcvr.getRcvrTopic(),rcvr.getId());
};
}
}
... ...
... ... @@ -6,13 +6,13 @@ package com.sunyo.wlpt.message.bus.service.utils;
* 时间:2020/7/1 9:26
*/
public class IdUtils {
private static IdWorker idWorker = new IdWorker();
/**
* 静态工具类
*
* @return id
*/
public static synchronized String generateId() {
IdWorker idWorker = new IdWorker();
long nextId = idWorker.nextId();
String id = String.valueOf(nextId);
return id;
... ...