Browse Source

优化动态网关,支持读取自定义namespace配置

test
smallchill 5 years ago
parent
commit
0fbc53868d
  1. 8
      blade-gateway/src/main/java/org/springblade/gateway/dynamic/DynamicRouteServiceListener.java
  2. 2
      blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

8
blade-gateway/src/main/java/org/springblade/gateway/dynamic/DynamicRouteServiceListener.java

@ -20,6 +20,7 @@ import com.alibaba.cloud.nacos.NacosConfigProperties;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;
@ -31,6 +32,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.Executor;
/**
@ -63,8 +65,10 @@ public class DynamicRouteServiceListener {
try {
String dataId = NacosConstant.dataId(bladeProperties.getName(), bladeProperties.getEnv(), NacosConstant.NACOS_CONFIG_JSON_FORMAT);
String group = nacosConfigProperties.getGroup();
String serverAddr = nacosDiscoveryProperties.getServerAddr();
ConfigService configService = NacosFactory.createConfigService(serverAddr);
Properties properties = new Properties();
properties.setProperty(PropertyKeyConst.SERVER_ADDR, nacosDiscoveryProperties.getServerAddr());
properties.setProperty(PropertyKeyConst.NAMESPACE, nacosDiscoveryProperties.getNamespace());
ConfigService configService = NacosFactory.createConfigService(properties);
configService.addListener(dataId, group, new Listener() {
@Override
public void receiveConfigInfo(String configInfo) {

2
blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java

@ -69,7 +69,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, User> implement
Integer accountNumber = tenant.getAccountNumber();
Integer tenantCount = baseMapper.selectCount(Wrappers.<User>query().lambda().eq(User::getTenantId, tenantId));
if (accountNumber != null && accountNumber > 0 && accountNumber < tenantCount) {
throw new ServiceException("当前租户已到最大账号额度");
throw new ServiceException("当前租户已到最大账号额度!");
}
}
if (Func.isNotEmpty(user.getPassword())) {

Loading…
Cancel
Save