mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
4.4.0
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-parent</artifactId>
|
||||
<version>4.3.4-SNAPSHOT</version>
|
||||
<version>4.4.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
|
@@ -10,7 +10,6 @@ import com.gitee.sop.gatewaycommon.util.MyBeanUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -24,9 +23,6 @@ public class DbLimitConfigManager extends DefaultLimitConfigManager {
|
||||
@Autowired
|
||||
ConfigLimitMapper configLimitMapper;
|
||||
|
||||
@Autowired
|
||||
Environment environment;
|
||||
|
||||
@Override
|
||||
public void load(String serviceId) {
|
||||
Query query = new Query();
|
||||
|
@@ -4,19 +4,19 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.gitee.fastmybatis.core.query.Query;
|
||||
import com.gitee.sop.gateway.entity.ConfigServiceRoute;
|
||||
import com.gitee.sop.gateway.mapper.ConfigServiceRouteMapper;
|
||||
import com.gitee.sop.gatewaycommon.bean.BeanInitializer;
|
||||
import com.gitee.sop.gateway.mapper.SystemLockMapper;
|
||||
import com.gitee.sop.gatewaycommon.bean.InstanceDefinition;
|
||||
import com.gitee.sop.gatewaycommon.bean.ServiceBeanInitializer;
|
||||
import com.gitee.sop.gatewaycommon.bean.ServiceRouteInfo;
|
||||
import com.gitee.sop.gatewaycommon.route.RoutesProcessor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ public class DbRoutesProcessor implements RoutesProcessor {
|
||||
private ConfigServiceRouteMapper configServiceRouteMapper;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
private SystemLockMapper systemLockMapper;
|
||||
|
||||
@Override
|
||||
public void removeAllRoutes(String serviceId) {
|
||||
@@ -39,8 +39,17 @@ public class DbRoutesProcessor implements RoutesProcessor {
|
||||
configServiceRouteMapper.deleteByQuery(delServiceQuery);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public synchronized void saveRoutes(ServiceRouteInfo serviceRouteInfo, InstanceDefinition instance) {
|
||||
// 抢锁,没抢到阻塞在这里
|
||||
systemLockMapper.lock();
|
||||
String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
|
||||
int result = systemLockMapper.insert(time + serviceRouteInfo.getMd5());
|
||||
// 抢到锁,插入失败,表示其它实例已经处理完毕,这里直接返回
|
||||
if (result == 0) {
|
||||
return;
|
||||
}
|
||||
log.info("保存路由信息到数据库,instance: {}", instance);
|
||||
String serviceId = serviceRouteInfo.getServiceId();
|
||||
List<ConfigServiceRoute> configServiceRoutes = serviceRouteInfo
|
||||
@@ -72,13 +81,6 @@ public class DbRoutesProcessor implements RoutesProcessor {
|
||||
if (CollectionUtils.isNotEmpty(configServiceRoutes)) {
|
||||
// 批量保存
|
||||
configServiceRouteMapper.saveBatch(configServiceRoutes);
|
||||
// 后续处理操作
|
||||
this.initServiceBeanInitializer(serviceId);
|
||||
}
|
||||
}
|
||||
|
||||
private void initServiceBeanInitializer(String serviceId) {
|
||||
Map<String, ServiceBeanInitializer> serviceBeanInitializerMap = applicationContext.getBeansOfType(ServiceBeanInitializer.class);
|
||||
serviceBeanInitializerMap.values().forEach(serviceBeanInitializer -> serviceBeanInitializer.load(serviceId));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,27 @@
|
||||
package com.gitee.sop.gateway.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.ResultType;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
/**
|
||||
* @author tanghc
|
||||
*/
|
||||
@Mapper
|
||||
public interface SystemLockMapper {
|
||||
|
||||
/**
|
||||
* 插入唯一值
|
||||
* @param content 唯一值
|
||||
* @return 1:返回成功,0:插入失败
|
||||
*/
|
||||
@Insert("INSERT IGNORE INTO system_lock(content) VALUES (#{content})")
|
||||
@ResultType(int.class)
|
||||
int insert(@Param("content") String content);
|
||||
|
||||
@Select("SELECT id FROM system_lock WHERE id=1 FOR UPDATE")
|
||||
@ResultType(long.class)
|
||||
long lock();
|
||||
}
|
Reference in New Issue
Block a user