You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2021/04/08 07:27:49 UTC
[dubbo] branch master updated: compatible Switch to interface level
service discovery when the registry does not support service introspection
architecture (#7506)
This is an automated email from the ASF dual-hosted git repository.
albumenj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new c60a8f0 compatible Switch to interface level service discovery when the registry does not support service introspection architecture (#7506)
c60a8f0 is described below
commit c60a8f000b130071882e46180f2e185b9bde64a9
Author: xiaoheng1 <20...@qq.com>
AuthorDate: Thu Apr 8 15:27:33 2021 +0800
compatible Switch to interface level service discovery when the registry does not support service introspection architecture (#7506)
* fix #7505 compatible Switch to interface level service discovery when the registry does not support service introspection architecture
* adjust the abnormal range
* add log.
* delete multicast service discovery.
* fix rmi test case
* add override annotation
---
.../client/migration/MigrationInvoker.java | 6 ++
.../InterfaceCompatibleRegistryProtocol.java | 18 +++++-
.../registry/support/AbstractRegistryFactory.java | 4 ++
.../multicast/MulticastServiceDiscovery.java | 66 ----------------------
...g.apache.dubbo.registry.client.ServiceDiscovery | 1 -
...e.dubbo.registry.client.ServiceDiscoveryFactory | 1 -
.../registry/redis/RedisServiceDiscovery.java | 64 ---------------------
.../redis/RedisServiceDiscoveryFactory.java | 30 ----------
...g.apache.dubbo.registry.client.ServiceDiscovery | 1 -
...e.dubbo.registry.client.ServiceDiscoveryFactory | 1 -
.../dubbo/rpc/protocol/rmi/RmiProtocolTest.java | 7 ++-
11 files changed, 32 insertions(+), 167 deletions(-)
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
index 2139d3b..b6ec32d 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/migration/MigrationInvoker.java
@@ -258,6 +258,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
this.invokersChanged.set(true);
}
+ @Override
public synchronized void destroyServiceDiscoveryInvoker(ClusterInvoker<?> serviceDiscoveryInvoker) {
if (checkInvokerAvailable(this.invoker)) {
this.currentAvailableInvoker = this.invoker;
@@ -270,6 +271,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
}
}
+ @Override
public synchronized void discardServiceDiscoveryInvokerAddress(ClusterInvoker<?> serviceDiscoveryInvoker) {
if (checkInvokerAvailable(this.invoker)) {
this.currentAvailableInvoker = this.invoker;
@@ -282,6 +284,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
}
}
+ @Override
public synchronized void refreshServiceDiscoveryInvoker() {
clearListener(serviceDiscoveryInvoker);
if (needRefresh(serviceDiscoveryInvoker)) {
@@ -318,6 +321,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
directory.setInvokersChangedListener(listener);
}
+ @Override
public synchronized void refreshInterfaceInvoker() {
clearListener(invoker);
if (needRefresh(invoker)) {
@@ -335,6 +339,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
}
}
+ @Override
public synchronized void destroyInterfaceInvoker(ClusterInvoker<T> invoker) {
if (checkInvokerAvailable(this.serviceDiscoveryInvoker)) {
this.currentAvailableInvoker = this.serviceDiscoveryInvoker;
@@ -347,6 +352,7 @@ public class MigrationInvoker<T> implements MigrationClusterInvoker<T> {
}
}
+ @Override
public synchronized void discardInterfaceInvokerAddress(ClusterInvoker<T> invoker) {
if (this.serviceDiscoveryInvoker != null) {
this.currentAvailableInvoker = this.serviceDiscoveryInvoker;
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
index b7374a3..62f9f7e 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/integration/InterfaceCompatibleRegistryProtocol.java
@@ -18,9 +18,12 @@ package org.apache.dubbo.registry.integration;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.URLBuilder;
+import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistryDirectory;
import org.apache.dubbo.registry.client.migration.MigrationInvoker;
+import org.apache.dubbo.registry.support.AbstractRegistryFactory;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.cluster.Cluster;
import org.apache.dubbo.rpc.cluster.ClusterInvoker;
@@ -34,6 +37,8 @@ import static org.apache.dubbo.registry.Constants.DEFAULT_REGISTRY;
*/
public class InterfaceCompatibleRegistryProtocol extends RegistryProtocol {
+ private final static Logger logger = LoggerFactory.getLogger(InterfaceCompatibleRegistryProtocol.class);
+
@Override
protected URL getRegistryUrl(Invoker<?> originInvoker) {
URL registryUrl = originInvoker.getUrl();
@@ -60,12 +65,21 @@ public class InterfaceCompatibleRegistryProtocol extends RegistryProtocol {
@Override
public <T> ClusterInvoker<T> getServiceDiscoveryInvoker(Cluster cluster, Registry registry, Class<T> type, URL url) {
- registry = registryFactory.getRegistry(super.getRegistryUrl(url));
+ try {
+ registry = registryFactory.getRegistry(super.getRegistryUrl(url));
+ } catch (IllegalStateException e) {
+ String protocol = url.getProtocol();
+ logger.warn(protocol + " do not support service discovery, automatically switch to interface-level service discovery.");
+ registry = AbstractRegistryFactory.getDefaultNopRegistryIfNotSupportServiceDiscovery();
+ }
+
DynamicDirectory<T> directory = new ServiceDiscoveryRegistryDirectory<>(type, url);
return doCreateInvoker(directory, cluster, registry, type);
}
- protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry, Class<T> type, URL url, URL consumerUrl) {
+ @Override
+ protected <T> ClusterInvoker<T> getMigrationInvoker(RegistryProtocol registryProtocol, Cluster cluster, Registry registry,
+ Class<T> type, URL url, URL consumerUrl) {
// ClusterInvoker<T> invoker = getInvoker(cluster, registry, type, url);
return new MigrationInvoker<T>(registryProtocol, cluster, registry, type, url, consumerUrl);
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
index ed602cb..4093f50 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/support/AbstractRegistryFactory.java
@@ -118,6 +118,10 @@ public abstract class AbstractRegistryFactory implements RegistryFactory {
return null;
}
+ public static Registry getDefaultNopRegistryIfNotSupportServiceDiscovery() {
+ return DEFAULT_NOP_REGISTRY;
+ }
+
@Override
public Registry getRegistry(URL url) {
diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastServiceDiscovery.java b/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastServiceDiscovery.java
deleted file mode 100644
index e49fbae..0000000
--- a/dubbo-registry/dubbo-registry-multicast/src/main/java/org/apache/dubbo/registry/multicast/MulticastServiceDiscovery.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.multicast;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.client.AbstractServiceDiscovery;
-import org.apache.dubbo.registry.client.ServiceInstance;
-
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * TODO: make multicast protocol support Service Discovery
- */
-public class MulticastServiceDiscovery extends AbstractServiceDiscovery {
- private URL registryURL;
-
- @Override
- public void initialize(URL registryURL) throws Exception {
- this.registryURL = registryURL;
- }
-
- @Override
- public void destroy() throws Exception {
-
- }
-
- @Override
- public void doRegister(ServiceInstance serviceInstance) {
-
- }
-
- @Override
- public void doUpdate(ServiceInstance serviceInstance) {
-
- }
-
- @Override
- public void unregister(ServiceInstance serviceInstance) throws RuntimeException {
- this.serviceInstance = null;
- }
-
- @Override
- public Set<String> getServices() {
- return Collections.singleton("Unsupported Operation");
- }
-
- @Override
- public URL getUrl() {
- return registryURL;
- }
-}
diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery b/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
deleted file mode 100644
index 091b549..0000000
--- a/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
+++ /dev/null
@@ -1 +0,0 @@
-multicast=org.apache.dubbo.registry.multicast.MulticastServiceDiscovery
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
deleted file mode 100644
index 03eb6fa..0000000
--- a/dubbo-registry/dubbo-registry-multicast/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
+++ /dev/null
@@ -1 +0,0 @@
-multicast=org.apache.dubbo.registry.multicast.MulticastServiceDiscoveryFactory
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscovery.java b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscovery.java
deleted file mode 100644
index 211f8b2..0000000
--- a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscovery.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.redis;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.client.AbstractServiceDiscovery;
-import org.apache.dubbo.registry.client.ServiceInstance;
-
-import java.util.Collections;
-import java.util.Set;
-
-public class RedisServiceDiscovery extends AbstractServiceDiscovery {
- private URL registryURL;
-
- @Override
- public void initialize(URL registryURL) throws Exception {
- this.registryURL = registryURL;
- }
-
- @Override
- public void destroy() throws Exception {
-
- }
-
- @Override
- public void doRegister(ServiceInstance serviceInstance) {
-
- }
-
- @Override
- public void doUpdate(ServiceInstance serviceInstance) {
-
- }
-
- @Override
- public void unregister(ServiceInstance serviceInstance) throws RuntimeException {
- this.serviceInstance = null;
- }
-
- @Override
- public Set<String> getServices() {
- return Collections.singleton("Unsupported Operation");
- }
-
- @Override
- public URL getUrl() {
- return registryURL;
- }
-
-}
diff --git a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscoveryFactory.java b/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscoveryFactory.java
deleted file mode 100644
index be6434e..0000000
--- a/dubbo-registry/dubbo-registry-redis/src/main/java/org/apache/dubbo/registry/redis/RedisServiceDiscoveryFactory.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.dubbo.registry.redis;
-
-import org.apache.dubbo.common.URL;
-import org.apache.dubbo.registry.client.AbstractServiceDiscoveryFactory;
-import org.apache.dubbo.registry.client.ServiceDiscovery;
-
-public class RedisServiceDiscoveryFactory extends AbstractServiceDiscoveryFactory {
-
- @Override
- protected ServiceDiscovery createDiscovery(URL registryURL) {
- return new RedisServiceDiscovery();
- }
-
-}
diff --git a/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery b/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
deleted file mode 100644
index f10e96e..0000000
--- a/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscovery
+++ /dev/null
@@ -1 +0,0 @@
-redis=org.apache.dubbo.registry.redis.RedisServiceDiscovery
\ No newline at end of file
diff --git a/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory b/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
deleted file mode 100644
index ecfeb37..0000000
--- a/dubbo-registry/dubbo-registry-redis/src/main/resources/META-INF/dubbo/internal/org.apache.dubbo.registry.client.ServiceDiscoveryFactory
+++ /dev/null
@@ -1 +0,0 @@
-redis=org.apache.dubbo.registry.redis.RedisServiceDiscoveryFactory
\ No newline at end of file
diff --git a/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java b/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java
index a1b9af2..ab4e57e 100644
--- a/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java
+++ b/dubbo-rpc/dubbo-rpc-rmi/src/test/java/org/apache/dubbo/rpc/protocol/rmi/RmiProtocolTest.java
@@ -38,7 +38,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class RmiProtocolTest {
private Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getAdaptiveExtension();
private ProxyFactory proxy = ExtensionLoader.getExtensionLoader(ProxyFactory.class).getAdaptiveExtension();
- int availablePort = NetUtils.getAvailablePort();
/*
@Test
@@ -49,6 +48,7 @@ public class RmiProtocolTest {
*/
@Test
public void testRmiProtocolTimeout() throws Exception {
+ int availablePort = NetUtils.getAvailablePort();
System.setProperty("sun.rmi.transport.tcp.responseTimeout", "1000");
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:" + availablePort + "/TestService")));
@@ -68,6 +68,7 @@ public class RmiProtocolTest {
@Test
public void testRmiProtocol() throws Exception {
{
+ int availablePort = NetUtils.getAvailablePort();
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:" + availablePort + "/TestService")));
@@ -99,6 +100,7 @@ public class RmiProtocolTest {
@Disabled
@Test
public void testRmiProtocol_echoService() throws Exception {
+ int availablePort = NetUtils.getAvailablePort();
DemoService service = new DemoServiceImpl();
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, URL.valueOf("rmi://127.0.0.1:" + availablePort + "/TestService")));
@@ -110,6 +112,7 @@ public class RmiProtocolTest {
rpcExporter.unexport();
+ availablePort = NetUtils.getAvailablePort();
RemoteService remoteService = new RemoteServiceImpl();
rpcExporter = protocol.export(proxy.getInvoker(remoteService, RemoteService.class, URL.valueOf("rmi://127.0.0.1:" + availablePort + "/remoteService")));
@@ -124,6 +127,7 @@ public class RmiProtocolTest {
@Test
public void testGenericInvoke() {
+ int availablePort = NetUtils.getAvailablePort();
DemoService service = new DemoServiceImpl();
URL url = URL.valueOf("rmi://127.0.0.1:" + availablePort + "/" + DemoService.class.getName() + "?release=2.7.0");
Exporter<DemoService> exporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));
@@ -138,6 +142,7 @@ public class RmiProtocolTest {
@Test
public void testRemoteApplicationName() throws Exception {
+ int availablePort = NetUtils.getAvailablePort();
DemoService service = new DemoServiceImpl();
URL url = URL.valueOf("rmi://127.0.0.1:" + availablePort + "/TestService?release=2.7.0").addParameter("application", "consumer");
Exporter<?> rpcExporter = protocol.export(proxy.getInvoker(service, DemoService.class, url));