19
19
import org .apache .dubbo .common .URL ;
20
20
import org .apache .dubbo .common .URLBuilder ;
21
21
import org .apache .dubbo .common .Version ;
22
+ import org .apache .dubbo .common .config .ConfigurationUtils ;
22
23
import org .apache .dubbo .common .extension .ExtensionLoader ;
23
24
import org .apache .dubbo .common .logger .Logger ;
24
25
import org .apache .dubbo .common .logger .LoggerFactory ;
33
34
import org .apache .dubbo .rpc .RpcException ;
34
35
import org .apache .dubbo .rpc .cluster .Cluster ;
35
36
import org .apache .dubbo .rpc .cluster .Configurator ;
37
+ import org .apache .dubbo .rpc .cluster .Constants ;
36
38
import org .apache .dubbo .rpc .cluster .RouterChain ;
37
39
import org .apache .dubbo .rpc .cluster .RouterFactory ;
38
40
import org .apache .dubbo .rpc .cluster .directory .AbstractDirectory ;
@@ -94,6 +96,11 @@ public abstract class DynamicDirectory<T> extends AbstractDirectory<T> implement
94
96
95
97
protected ServiceInstancesChangedListener serviceListener ;
96
98
99
+ /**
100
+ * Should continue route if directory is empty
101
+ */
102
+ private final boolean shouldFailFast ;
103
+
97
104
public DynamicDirectory (Class <T > serviceType , URL url ) {
98
105
super (url , true );
99
106
@@ -114,6 +121,7 @@ public DynamicDirectory(Class<T> serviceType, URL url) {
114
121
this .overrideDirectoryUrl = this .directoryUrl = turnRegistryUrlToConsumerUrl (url );
115
122
String group = directoryUrl .getParameter (GROUP_KEY , "" );
116
123
this .multiGroup = group != null && (ANY_VALUE .equals (group ) || group .contains ("," ));
124
+ this .shouldFailFast = Boolean .parseBoolean (ConfigurationUtils .getProperty (Constants .SHOULD_FAIL_FAST_KEY , "true" ));
117
125
}
118
126
119
127
@ Override
@@ -162,7 +170,7 @@ public void unSubscribe(URL url) {
162
170
163
171
@ Override
164
172
public List <Invoker <T >> doList (Invocation invocation ) {
165
- if (forbidden ) {
173
+ if (forbidden && shouldFailFast ) {
166
174
// 1. No service provider 2. Service providers are disabled
167
175
throw new RpcException (RpcException .FORBIDDEN_EXCEPTION , "No provider available from registry " +
168
176
getUrl ().getAddress () + " for service " + getConsumerUrl ().getServiceKey () + " on consumer " +
0 commit comments