Commit b451b5a6 by Nepxion

增加注册失败后事件发布/订阅功能

parent 93beba08
......@@ -11,6 +11,7 @@ package com.nepxion.discovery.plugin.framework.constant;
public class PluginConstant {
public static final String SPRING_APPLICATION_REGISTER_CONTROL_ENABLED = "spring.application.register.control.enabled";
public static final String SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED = "spring.application.register.failure.event.enabled";
public static final String SPRING_APPLICATION_DISCOVERY_CONTROL_ENABLED = "spring.application.discovery.control.enabled";
public static final String SPRING_APPLICATION_DISCOVERY_REMOTE_CONFIG_ENABLED = "spring.application.discovery.remote.config.enabled";
......
......@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.serviceregistry.Registration;
import com.nepxion.discovery.plugin.framework.adapter.PluginAdapter;
import com.nepxion.discovery.plugin.framework.constant.PluginConstant;
import com.nepxion.discovery.plugin.framework.entity.FilterEntity;
import com.nepxion.discovery.plugin.framework.entity.FilterType;
import com.nepxion.discovery.plugin.framework.entity.RegisterEntity;
......@@ -113,7 +114,10 @@ public class IpAddressFilterRegisterListener extends AbstractRegisterListener {
}
private void onRegisterFaiure(FilterType filterType, String serviceId, String ipAddress, int port) {
pluginPublisher.asyncPublish(new RegisterFaiureEvent(filterType, serviceId, ipAddress, port));
Boolean registerFailureEventEnabled = environment.getProperty(PluginConstant.SPRING_APPLICATION_REGISTER_FAILURE_EVENT_ENABLED, Boolean.class, Boolean.FALSE);
if (registerFailureEventEnabled) {
pluginPublisher.asyncPublish(new RegisterFaiureEvent(filterType, serviceId, ipAddress, port));
}
throw new PluginException(ipAddress + " isn't allowed to register to Discovery server, because it is in blacklist");
}
......
......@@ -19,8 +19,8 @@ management.health.consul.enabled=false
# Plugin config
# 开启和关闭服务注册层面的控制。一旦关闭,服务注册的黑/白名单过滤功能将失效。缺失则默认为true
spring.application.register.control.enabled=true
# 开启和关闭禁止注册后发送异步事件通知。一旦关闭,禁止注册后,不会发送异步事件通知。缺失则默认为true
spring.application.register.failure.event.enabled=true
# 开启和关闭禁止注册后发送异步事件通知。一旦关闭,禁止注册后,不会发送异步事件通知。缺失则默认为false
spring.application.register.failure.event.enabled=false
# 开启和关闭服务发现层面的控制。一旦关闭,服务多版本调用的控制功能将失效,动态屏蔽指定IP地址的服务实例被发现的功能将失效。缺失则默认为true
spring.application.discovery.control.enabled=true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment