作者 朱兆平

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

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