* Add router fail fast option (Backport #9388) * update
This commit is contained in:
parent
326fb7250c
commit
bf29eb5706
|
|
@ -103,4 +103,6 @@ public interface Constants {
|
|||
* prefix of arguments router key
|
||||
*/
|
||||
String ARGUMENTS = "arguments";
|
||||
|
||||
String SHOULD_FAIL_FAST_KEY = "dubbo.router.should-fail-fast";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package org.apache.dubbo.registry.integration;
|
|||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.URLBuilder;
|
||||
import org.apache.dubbo.common.Version;
|
||||
import org.apache.dubbo.common.config.ConfigurationUtils;
|
||||
import org.apache.dubbo.common.extension.ExtensionLoader;
|
||||
import org.apache.dubbo.common.logger.Logger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
|
|
@ -33,6 +34,7 @@ import org.apache.dubbo.rpc.Protocol;
|
|||
import org.apache.dubbo.rpc.RpcException;
|
||||
import org.apache.dubbo.rpc.cluster.Cluster;
|
||||
import org.apache.dubbo.rpc.cluster.Configurator;
|
||||
import org.apache.dubbo.rpc.cluster.Constants;
|
||||
import org.apache.dubbo.rpc.cluster.RouterChain;
|
||||
import org.apache.dubbo.rpc.cluster.RouterFactory;
|
||||
import org.apache.dubbo.rpc.cluster.directory.AbstractDirectory;
|
||||
|
|
@ -94,6 +96,11 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
|
|||
|
||||
protected ServiceInstancesChangedListener serviceListener;
|
||||
|
||||
/**
|
||||
* Should continue route if directory is empty
|
||||
*/
|
||||
private final boolean shouldFailFast;
|
||||
|
||||
public DynamicDirectory(Class<T> serviceType, URL url) {
|
||||
super(url, true);
|
||||
|
||||
|
|
@ -114,6 +121,7 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
|
|||
this.overrideDirectoryUrl = this.directoryUrl = turnRegistryUrlToConsumerUrl(url);
|
||||
String group = directoryUrl.getParameter(GROUP_KEY, "");
|
||||
this.multiGroup = group != null && (ANY_VALUE.equals(group) || group.contains(","));
|
||||
this.shouldFailFast = Boolean.parseBoolean(ConfigurationUtils.getProperty(Constants.SHOULD_FAIL_FAST_KEY, "true"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -162,7 +170,7 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
|
|||
|
||||
@Override
|
||||
public List<Invoker<T>> doList(Invocation invocation) {
|
||||
if (forbidden) {
|
||||
if (forbidden && shouldFailFast) {
|
||||
// 1. No service provider 2. Service providers are disabled
|
||||
throw new RpcException(RpcException.FORBIDDEN_EXCEPTION, "No provider available from registry " +
|
||||
getUrl().getAddress() + " for service " + getConsumerUrl().getServiceKey() + " on consumer " +
|
||||
|
|
|
|||
Loading…
Reference in New Issue