This commit is contained in:
Redkale
2020-06-05 18:44:51 +08:00
parent 531b00b6fd
commit a7e5fad571
2 changed files with 12 additions and 4 deletions

View File

@@ -49,11 +49,15 @@
【节点全局唯一】 【节点全局唯一】
第三方服务发现管理接口 第三方服务发现管理接口
value 类名必须是org.redkale.cluster.ClusterAgent的子类 value 类名必须是org.redkale.cluster.ClusterAgent的子类
waits: 注销服务后是否需要等待检查周期时间后再进行Service销毁默认值为false
当一个Service进行服务注销后不能立刻销毁Service因为健康检测是有间隔时间差的
需要等待一个健康检测周期时间,让其他进程都更新完服务列表。
如果使用MQ可以设置为false如果对服务健壮性要求高建议设置为true
protocols: 服务发现可以处理的协议, 默认值为: SNCP, 多个协议用分号;隔开 protocols: 服务发现可以处理的协议, 默认值为: SNCP, 多个协议用分号;隔开
ports: 服务发现可以处理的端口, 多个端口用分号;隔开 ports: 服务发现可以处理的端口, 多个端口用分号;隔开
--> -->
<!-- <!--
<cluster value="org.redkalex.cluster.consul.ConsulClusterAgent" protocols="SNCP" ports="7070;7071"> <cluster value="org.redkalex.cluster.consul.ConsulClusterAgent" waits="false" protocols="SNCP" ports="7070;7071">
<property name="xxxxxx" value="XXXXXXXX"/> <property name="xxxxxx" value="XXXXXXXX"/>
</cluster> </cluster>
--> -->

View File

@@ -36,6 +36,8 @@ public abstract class ClusterAgent {
protected String name; protected String name;
protected boolean waits;
protected String[] protocols; //必须全大写 protected String[] protocols; //必须全大写
protected int[] ports; protected int[] ports;
@@ -51,6 +53,7 @@ public abstract class ClusterAgent {
public void init(AnyValue config) { public void init(AnyValue config) {
this.config = config; this.config = config;
this.name = config.getValue("name", ""); this.name = config.getValue("name", "");
this.waits = config.getBoolValue("waits", false);
{ {
String ps = config.getValue("protocols", "").toUpperCase(); String ps = config.getValue("protocols", "").toUpperCase();
if (ps == null || ps.isEmpty()) ps = "SNCP;HTTP"; if (ps == null || ps.isEmpty()) ps = "SNCP;HTTP";
@@ -123,13 +126,14 @@ public abstract class ClusterAgent {
} }
protected void afterDeregister(NodeServer ns, String protocol) { protected void afterDeregister(NodeServer ns, String protocol) {
if (!this.waits) return;
int s = intervalCheckSeconds(); int s = intervalCheckSeconds();
if (s / 2 > 0) { //暂停,弥补其他依赖本进程服务的周期偏差 if (s > 0) { //暂停,弥补其他依赖本进程服务的周期偏差
try { try {
Thread.sleep(s * 1000 / 2); Thread.sleep(s * 1000);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
} }
logger.info(this.getClass().getSimpleName() + " sleep " + s * 1000 / 2 + "ms after deregister"); logger.info(this.getClass().getSimpleName() + " wait for " + s * 1000 + "ms after deregister");
} }
} }