diff --git a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java index b7df466335e..437024d9990 100644 --- a/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java +++ b/dubbo-bootstrap/src/main/java/org/apache/dubbo/bootstrap/DubboBootstrap.java @@ -63,10 +63,10 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Set; import java.util.SortedSet; -import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Condition; @@ -75,6 +75,7 @@ import java.util.function.Consumer; import static java.util.Arrays.asList; +import static java.util.Collections.sort; import static java.util.concurrent.Executors.newSingleThreadExecutor; import static org.apache.dubbo.common.config.ConfigurationUtils.parseProperties; import static org.apache.dubbo.common.config.configcenter.DynamicConfiguration.getDynamicConfiguration; @@ -140,7 +141,7 @@ public class DubboBootstrap extends GenericEventListener implements Lifecycle { private volatile MetadataServiceExporter metadataServiceExporter; - private SortedSet serviceDiscoveries = new ConcurrentSkipListSet<>(); + private volatile List serviceDiscoveries = new LinkedList<>(); public DubboBootstrap() { DubboShutdownHook.getDubboShutdownHook().register(); @@ -153,7 +154,10 @@ public DubboBootstrap() { * @see {@linkplan org.apache.dubbo.registry.client.EventPublishingServiceDiscovery} */ public void onServiceDiscoveryInitializing(ServiceDiscoveryInitializingEvent event) { - serviceDiscoveries.add(event.getSource()); + executeMutually(() -> { + serviceDiscoveries.add(event.getSource()); + sort(serviceDiscoveries); + }); } /** diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java index bf1fe0ae5f8..96a865f3f61 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceConsumerBootstrap.java @@ -35,6 +35,7 @@ public static void main(String[] args) throws Exception { .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry.type=service&subscribed.services=dubbo-provider-demo")) // .metadataReport(new MetadataReportConfig("zookeeper://127.0.0.1:2181")) // Nacos + .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service&subscribed.services=dubbo-provider-demo")) // .registry("consul", builder -> builder.address("consul://127.0.0.1:8500?registry.type=service&subscribed.services=dubbo-provider-demo").group("namespace1")) .reference("echo", builder -> builder.interfaceClass(EchoService.class).protocol("dubbo")) .reference("user", builder -> builder.interfaceClass(UserService.class).protocol("rest")) diff --git a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java index 83ea7a12ffd..15bb814c2ba 100644 --- a/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java +++ b/dubbo-bootstrap/src/test/java/org/apache/dubbo/bootstrap/DubboServiceProvider2Bootstrap.java @@ -32,7 +32,7 @@ public static void main(String[] args) { // Zookeeper in service registry type .registry("zookeeper", builder -> builder.address("zookeeper://127.0.0.1:2181?registry.type=service")) // Nacos -// .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service")) + .registry("nacos", builder -> builder.address("nacos://127.0.0.1:8848?registry.type=service")) // .registry(RegistryBuilder.newBuilder().address("etcd3://127.0.0.1:2379?registry.type=service").build()) .protocol("dubbo", builder -> builder.port(20885).name("dubbo")) .protocol("rest", builder -> builder.port(9090).name("rest"))