group增加nodes属性

This commit is contained in:
redkale
2023-12-29 11:31:04 +08:00
parent fc420221cf
commit 6cade6a1da
4 changed files with 24 additions and 14 deletions

View File

@@ -109,11 +109,12 @@
一个组包含多个node 同一Service服务可以由多个进程提供这些进程称为一个GROUP且同一GROUP内的进程必须在同一机房或局域网内
name: 服务组ID长度不能超过11个字节. 默认为空字符串。 注意: name不能包含$符号。
protocol 值范围UDP TCP 默认TCP
nodes: 多个node节点值 例如:192.168.0.1:6060,192.168.0.2:6060
注意: 一个node只能所属一个group。只要存在protocol=SNCP的Server节点信息 就必须有group节点信息。
-->
<group name="" protocol="TCP">
<group name="" protocol="TCP" nodes="192.168.0.1:6060,192.168.0.2:6060">
<!--
需要将本地node的addr与port列在此处。
需要将本地node的addr与port列在此处, 也可以直接用nodes属性
同一个<node>节点值只能存在一个<group>节点内即同一个addr+port只能属于一个group。
addr: required IP地址
port: required 端口

View File

@@ -577,14 +577,25 @@ public final class Application {
//------------------------------------------------------------------------
for (AnyValue conf : config.getAnyValues("group")) {
final String group = conf.getValue("name", "");
if (group.indexOf('$') >= 0) {
throw new RedkaleException("<group> name cannot contains '$' in " + group);
if (group.indexOf('$') >= 0 || group.indexOf('.') >= 0) {
throw new RedkaleException("<group> name cannot contains '$', '.' in " + group);
}
final String protocol = conf.getValue("protocol", "TCP").toUpperCase();
if (!"TCP".equalsIgnoreCase(protocol) && !"UDP".equalsIgnoreCase(protocol)) {
throw new RedkaleException("Not supported Transport Protocol " + conf.getValue("protocol"));
}
SncpRpcGroup rg = sncpRpcGroups.computeIfAbsent(group, protocol);
String nodes = conf.getValue("nodes");
if (Utility.isNotEmpty(nodes)) {
for (String node : nodes.replace(',', ';').split(";")) {
if (Utility.isNotBlank(node)) {
int pos = node.indexOf(':');
String addr = node.substring(0, pos).trim();
int port = Integer.parseInt(node.substring(pos + 1).trim());
rg.putAddress(new InetSocketAddress(addr, port));
}
}
}
for (AnyValue node : conf.getAnyValues("node")) {
rg.putAddress(new InetSocketAddress(node.getValue("addr"), node.getIntValue("port")));
}