nacos数据库改postgresql后测试发现第二个服务无法注册成功问题。
@Test
public void testRegisterInstance() throws NacosException {
// nacos地址,用户和密码
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:9091");
properties.put(PropertyKeyConst.USERNAME, "nacos");
properties.put(PropertyKeyConst.PASSWORD, "nacos");
// 构建服务实例
Instance instance = new Instance();
instance.setIp("1.1.1.1");
instance.setPort(800);
instance.setWeight(2);
Map<String, String> map = new HashMap<>();
map.put("netType", "external");
map.put("version", "2.0");
instance.setMetadata(map);
// 创建NamingService
NamingService namingService = NacosFactory.createNamingService(properties);
// 通过NamingService注册服务实例,并指定服务名为 nacos.test.1
namingService.registerInstance("nacos.test.1", instance);
System.out.println("注册 nacos.test.1");
Instance instance2 = new Instance();
instance2.setIp("1.1.1.1");
instance2.setPort(801);
instance2.setWeight(2);
instance2.setMetadata(map);
NamingService namingService2 = NacosFactory.createNamingService(properties);
namingService2.registerInstance("nacos.test.2", instance2);
System.out.println("注册 nacos.test.2");
}
问题提示
ErrCode:500, ErrMsg:Request nacos server failed:
Caused by: ErrCode:301, ErrMsg:Connection is unregistered.
1,提示信息关键字 Connection is unregistered.
断点进入执行流程
2,调试流程发现问题
无效连接:connectionManager.checkValid(connectionId);
判断连接信息不足 connections
查看注册代码 register
判断注册限制 checkLimit
判断注册限制 isOverLimit
检查限制值 countLimit
3,定位问题产生原因
查询配置 countLimit
注释代码 ConnectionManagerTest.testOnEvent
测试产生 C:\Users\YHsoft\nacos\data\loader\limitRule
删除文件 limitRule