fail fast when protocol exp (#12361)

* fail fast when protocol exp

* use hasExtension

* Adjust the spi detection position

* remove unuse

* remove unuse
This commit is contained in:
wxbty 2023-06-12 20:47:02 +08:00 committed by GitHub
parent 3fa518505f
commit bde608ec3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -119,6 +119,18 @@ public class RegistryDirectory<T> extends DynamicDirectory<T> {
@Override
public void subscribe(URL url) {
// Fail-fast detection protocol spi
String queryProtocols = this.queryMap.get(PROTOCOL_KEY);
if (StringUtils.isNotBlank(queryProtocols)) {
String[] acceptProtocols = queryProtocols.split(",");
for (String acceptProtocol : acceptProtocols) {
if (!moduleModel.getApplicationModel().getExtensionLoader(Protocol.class).hasExtension(acceptProtocol)) {
throw new IllegalStateException("No such extension org.apache.dubbo.rpc.Protocol by name " + acceptProtocol + ", please check whether related SPI module is missing");
}
}
}
ApplicationModel applicationModel = url.getApplicationModel();
MetricsEventBus.post(RegistryEvent.toSubscribeEvent(applicationModel),() ->
{