Nacos Discovery supports registration for quick failed configurations

pull/2104/head
yuhuangbin 4 years ago
parent 480fa336bf
commit a2b2c2f8c1

@ -2,6 +2,7 @@ spring.application.name=service-consumer
server.port=18083 server.port=18083
management.endpoints.web.exposure.include=* management.endpoints.web.exposure.include=*
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.cloud.nacos.discovery.fail-fast=true
spring.cloud.nacos.username=nacos spring.cloud.nacos.username=nacos
spring.cloud.nacos.password=nacos spring.cloud.nacos.password=nacos

@ -207,6 +207,12 @@ public class NacosDiscoveryProperties {
*/ */
private boolean ephemeral = true; private boolean ephemeral = true;
/**
* Throw exceptions during service registration if true, otherwise, log error
* (defaults to true).
*/
private boolean failFast = true;
@Autowired @Autowired
private InetUtils inetUtils; private InetUtils inetUtils;
@ -486,6 +492,14 @@ public class NacosDiscoveryProperties {
this.ephemeral = ephemeral; this.ephemeral = ephemeral;
} }
public boolean isFailFast() {
return failFast;
}
public void setFailFast(boolean failFast) {
this.failFast = failFast;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) { if (this == o) {
@ -510,6 +524,7 @@ public class NacosDiscoveryProperties {
&& Objects.equals(secretKey, that.secretKey) && Objects.equals(secretKey, that.secretKey)
&& Objects.equals(heartBeatInterval, that.heartBeatInterval) && Objects.equals(heartBeatInterval, that.heartBeatInterval)
&& Objects.equals(heartBeatTimeout, that.heartBeatTimeout) && Objects.equals(heartBeatTimeout, that.heartBeatTimeout)
&& Objects.equals(failFast, that.failFast)
&& Objects.equals(ipDeleteTimeout, that.ipDeleteTimeout); && Objects.equals(ipDeleteTimeout, that.ipDeleteTimeout);
} }
@ -519,7 +534,7 @@ public class NacosDiscoveryProperties {
watchDelay, logName, service, weight, clusterName, group, watchDelay, logName, service, weight, clusterName, group,
namingLoadCacheAtStart, registerEnabled, ip, networkInterface, port, namingLoadCacheAtStart, registerEnabled, ip, networkInterface, port,
secure, accessKey, secretKey, heartBeatInterval, heartBeatTimeout, secure, accessKey, secretKey, heartBeatInterval, heartBeatTimeout,
ipDeleteTimeout, instanceEnabled, ephemeral); ipDeleteTimeout, instanceEnabled, ephemeral, failFast);
} }
@Override @Override
@ -535,7 +550,7 @@ public class NacosDiscoveryProperties {
+ ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey + ", port=" + port + ", secure=" + secure + ", accessKey='" + accessKey
+ '\'' + ", secretKey='" + secretKey + '\'' + ", heartBeatInterval=" + '\'' + ", secretKey='" + secretKey + '\'' + ", heartBeatInterval="
+ heartBeatInterval + ", heartBeatTimeout=" + heartBeatTimeout + heartBeatInterval + ", heartBeatTimeout=" + heartBeatTimeout
+ ", ipDeleteTimeout=" + ipDeleteTimeout + '}'; + ", ipDeleteTimeout=" + ipDeleteTimeout + ", failFast=" + failFast + '}';
} }
public void overrideFromEnv(Environment env) { public void overrideFromEnv(Environment env) {

@ -76,11 +76,15 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
instance.getIp(), instance.getPort()); instance.getIp(), instance.getPort());
} }
catch (Exception e) { catch (Exception e) {
log.error("nacos registry, {} register failed...{},", serviceId, if (nacosDiscoveryProperties.isFailFast()) {
registration.toString(), e); log.error("nacos registry, {} register failed...{},", serviceId,
// rethrow a RuntimeException if the registration is failed. registration.toString(), e);
// issue : https://github.com/alibaba/spring-cloud-alibaba/issues/1132 rethrowRuntimeException(e);
rethrowRuntimeException(e); }
else {
log.warn("Failfast is false. {} register failed...{},", serviceId,
registration.toString(), e);
}
} }
} }

Loading…
Cancel
Save