You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2020/08/05 04:23:28 UTC
[dubbo] branch 3.0-to-master updated: add Zookeeper MetadataReport
implementation (#6553)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0-to-master
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0-to-master by this push:
new 82ee2eb add Zookeeper MetadataReport implementation (#6553)
82ee2eb is described below
commit 82ee2eb50749820d0311c679bd2a0936356402c6
Author: 斩秋 <qu...@users.noreply.github.com>
AuthorDate: Wed Aug 5 12:23:11 2020 +0800
add Zookeeper MetadataReport implementation (#6553)
---
.../dubbo/config/utils/ConfigValidationUtils.java | 2 +-
.../dubbo-demo-service-consumer/pom.xml | 87 +++++++++++++++++
.../dubbo/demo/consumer/ApplicationZKConsumer.java | 69 +++++++++++++
.../src/main/resources/dubbo.properties | 1 +
.../src/main/resources/log4j.properties | 7 ++
.../main/resources/spring/dubbo-consumer-zk.xml | 38 ++++++++
.../dubbo-demo-service-provider/pom.xml | 107 +++++++++++++++++++++
.../dubbo/demo/provider/ApplicationZKProvider.java | 27 ++++++
.../dubbo/demo/provider/DemoServiceImpl.java | 53 ++++++++++
.../dubbo/demo/provider/GreetingServiceImpl.java | 29 ++++++
.../src/main/resources/dubbo.properties | 1 +
.../src/main/resources/log4j.properties | 7 ++
.../main/resources/spring/dubbo-provider-zk.xml | 43 +++++++++
dubbo-demo/dubbo-demo-service/pom.xml | 68 +++++++++++++
dubbo-demo/pom.xml | 1 +
.../store/zookeeper/ZookeeperMetadataReport.java | 35 +++++++
.../registry/client/ServiceDiscoveryRegistry.java | 8 +-
17 files changed, 578 insertions(+), 5 deletions(-)
diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
index 13e5fb1..4658157 100644
--- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
+++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java
@@ -214,7 +214,7 @@ public class ConfigValidationUtils {
if (provider) {
// for registries enabled service discovery, automatically register interface compatible addresses.
if (SERVICE_REGISTRY_PROTOCOL.equals(registryURL.getProtocol())
- && registryURL.getParameter(REGISTRY_DUPLICATE_KEY, true)
+ && registryURL.getParameter(REGISTRY_DUPLICATE_KEY, false)
&& registryNotExists(registryURL, registryList, REGISTRY_PROTOCOL)) {
URL interfaceCompatibleRegistryURL = URLBuilder.from(registryURL)
.setProtocol(REGISTRY_PROTOCOL)
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/pom.xml b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/pom.xml
new file mode 100644
index 0000000..40a94d2
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/pom.xml
@@ -0,0 +1,87 @@
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-demo-service</artifactId>
+ <version>${revision}</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>dubbo-demo-service-consumer</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+ <description>The demo consumer module of dubbo project</description>
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metadata-report-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-demo-interface</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-multicast</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metadata-report-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-config-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-netty4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-serialization-hessian2</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/java/org/apache/dubbo/demo/consumer/ApplicationZKConsumer.java b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/java/org/apache/dubbo/demo/consumer/ApplicationZKConsumer.java
new file mode 100644
index 0000000..549cb97
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/java/org/apache/dubbo/demo/consumer/ApplicationZKConsumer.java
@@ -0,0 +1,69 @@
+/*
+ * 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.demo.consumer;
+
+import org.apache.dubbo.demo.DemoService;
+import org.apache.dubbo.demo.GreetingService;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CompletableFuture;
+
+public class ApplicationZKConsumer {
+ /**
+ * In order to make sure multicast registry works, need to specify '-Djava.net.preferIPv4Stack=true' before
+ * launch the application
+ */
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer-zk.xml");
+ context.start();
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ GreetingService greetingService = context.getBean("greetingService", GreetingService.class);
+
+ new Thread(() -> {
+ while (true) {
+ try {
+ String greetings = greetingService.hello();
+ System.out.println(greetings + " from separated thread.");
+ } catch (Exception e) {
+ e.printStackTrace();;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+
+ while (true) {
+ try {
+ CompletableFuture<String> hello = demoService.sayHelloAsync("world");
+ System.out.println("result: " + hello.get());
+
+ String greetings = greetingService.hello();
+ System.out.println("result: " + greetings);
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Thread.sleep(1000);
+ }
+ }
+}
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/dubbo.properties b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..8c3cb25
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/dubbo.properties
@@ -0,0 +1 @@
+dubbo.application.qos.port=33333
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/log4j.properties b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/log4j.properties
new file mode 100644
index 0000000..2424381
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/spring/dubbo-consumer-zk.xml b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/spring/dubbo-consumer-zk.xml
new file mode 100644
index 0000000..b646af0
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-consumer/src/main/resources/spring/dubbo-consumer-zk.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <dubbo:application name="demo-service-consumer" metadata-type="remote">
+ <dubbo:parameter key="mapping-type" value="metadata"/>
+ </dubbo:application>
+
+ <dubbo:metadata-report address="zookeeper://127.0.0.1:2181"/>
+
+ <dubbo:registry address="zookeeper://127.0.0.1:2181?registry-type=service">
+ </dubbo:registry>
+
+ <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.demo.DemoService"/>
+
+ <dubbo:reference version="1.0.0" group="greeting" id="greetingService" check="false"
+ interface="org.apache.dubbo.demo.GreetingService"/>
+
+</beans>
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/pom.xml b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/pom.xml
new file mode 100644
index 0000000..74ef4a2
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/pom.xml
@@ -0,0 +1,107 @@
+<!--
+ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-demo-service</artifactId>
+ <version>${revision}</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>dubbo-demo-service-provider</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+ <description>The demo provider module of dubbo project</description>
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ <slf4j-log4j12.version>1.7.25</slf4j-log4j12.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-demo-interface</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-multicast</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba.nacos</groupId>
+ <artifactId>nacos-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metadata-report-nacos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metadata-report-zookeeper</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-rpc-dubbo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-config-spring</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-remoting-netty4</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-serialization-hessian2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-qos</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${slf4j-log4j12.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/ApplicationZKProvider.java b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/ApplicationZKProvider.java
new file mode 100644
index 0000000..0b078e9
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/ApplicationZKProvider.java
@@ -0,0 +1,27 @@
+/*
+ * 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.demo.provider;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class ApplicationZKProvider {
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider-zk.xml");
+ context.start();
+ System.in.read();
+ }
+}
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java
new file mode 100644
index 0000000..4bccce6
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/DemoServiceImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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.demo.provider;
+
+import org.apache.dubbo.demo.DemoService;
+import org.apache.dubbo.rpc.RpcContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.CompletableFuture;
+
+public class DemoServiceImpl implements DemoService {
+ private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class);
+
+ @Override
+ public String sayHello(String name) {
+ logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
+ }
+
+ @Override
+ public CompletableFuture<String> sayHelloAsync(String name) {
+ CompletableFuture<String> cf = CompletableFuture.supplyAsync(() -> {
+// try {
+// Thread.sleep(1000);
+// } catch (InterruptedException e) {
+// e.printStackTrace();
+// }
+ return "async result";
+ });
+ return cf;
+ }
+}
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java
new file mode 100644
index 0000000..cc1b5de
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/java/org/apache/dubbo/demo/provider/GreetingServiceImpl.java
@@ -0,0 +1,29 @@
+/*
+ * 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.demo.provider;
+
+import org.apache.dubbo.demo.GreetingService;
+
+/**
+ *
+ */
+public class GreetingServiceImpl implements GreetingService {
+ @Override
+ public String hello() {
+ return "Greetings!";
+ }
+}
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/dubbo.properties b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..ad602ba
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/dubbo.properties
@@ -0,0 +1 @@
+dubbo.application.qos.port=22222
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/log4j.properties b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/log4j.properties
@@ -0,0 +1,7 @@
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy HH:mm:ss:SSS z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/spring/dubbo-provider-zk.xml b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/spring/dubbo-provider-zk.xml
new file mode 100644
index 0000000..7ba04ef
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/dubbo-demo-service-provider/src/main/resources/spring/dubbo-provider-zk.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <dubbo:application name="demo-service-provider" metadata-type="remote">
+ <dubbo:parameter key="mapping-type" value="metadata"/>
+ </dubbo:application>
+
+ <dubbo:config-center address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:metadata-report address="zookeeper://127.0.0.1:2181"/>
+ <dubbo:registry id="registry1" address="zookeeper://127.0.0.1:2181?registry-type=service">
+ <dubbo:parameter key="duplicate" value="false" />
+ </dubbo:registry>
+
+ <dubbo:protocol name="dubbo" port="-1"/>
+
+ <bean id="demoService" class="org.apache.dubbo.demo.provider.DemoServiceImpl"/>
+ <bean id="greetingService" class="org.apache.dubbo.demo.provider.GreetingServiceImpl"/>
+
+ <dubbo:service interface="org.apache.dubbo.demo.DemoService" timeout="3000" ref="demoService" registry="registry1"/>
+ <dubbo:service version="1.0.0" group="greeting" timeout="5000" interface="org.apache.dubbo.demo.GreetingService"
+ ref="greetingService"/>
+
+</beans>
diff --git a/dubbo-demo/dubbo-demo-service/pom.xml b/dubbo-demo/dubbo-demo-service/pom.xml
new file mode 100644
index 0000000..19520b6
--- /dev/null
+++ b/dubbo-demo/dubbo-demo-service/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-demo</artifactId>
+ <version>${revision}</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+
+ <artifactId>dubbo-demo-service</artifactId>
+
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ <spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+ </properties>
+
+ <modules>
+ <module>dubbo-demo-service-provider</module>
+ <module>dubbo-demo-service-consumer</module>
+ </modules>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-metadata-report-zookeeper</artifactId>
+ <version>${project.parent.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>${spring-boot-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/dubbo-demo/pom.xml b/dubbo-demo/pom.xml
index e636a23..af569a2 100644
--- a/dubbo-demo/pom.xml
+++ b/dubbo-demo/pom.xml
@@ -33,6 +33,7 @@
<modules>
<module>dubbo-demo-interface</module>
<module>dubbo-demo-xml</module>
+ <module>dubbo-demo-service</module>
<module>dubbo-demo-annotation</module>
<module>dubbo-demo-api</module>
</modules>
diff --git a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
index 9ca2e42..e31886a 100644
--- a/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
+++ b/dubbo-metadata/dubbo-metadata-report-zookeeper/src/main/java/org/apache/dubbo/metadata/store/zookeeper/ZookeeperMetadataReport.java
@@ -16,10 +16,13 @@
*/
package org.apache.dubbo.metadata.store.zookeeper;
+import com.google.gson.Gson;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.StringUtils;
+import org.apache.dubbo.metadata.MappingListener;
+import org.apache.dubbo.metadata.MetadataInfo;
import org.apache.dubbo.metadata.report.identifier.BaseMetadataIdentifier;
import org.apache.dubbo.metadata.report.identifier.KeyTypeEnum;
import org.apache.dubbo.metadata.report.identifier.MetadataIdentifier;
@@ -32,7 +35,12 @@ import org.apache.dubbo.remoting.zookeeper.ZookeeperTransporter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
@@ -48,6 +56,8 @@ public class ZookeeperMetadataReport extends AbstractMetadataReport {
final ZookeeperClient zkClient;
+ private Gson gson = new Gson();
+
public ZookeeperMetadataReport(URL url, ZookeeperTransporter zookeeperTransporter) {
super(url);
if (url.isAnyHost()) {
@@ -120,4 +130,29 @@ public class ZookeeperMetadataReport extends AbstractMetadataReport {
return toRootDir() + metadataIdentifier.getUniqueKey(KeyTypeEnum.PATH);
}
+ @Override
+ public void publishAppMetadata(SubscriberMetadataIdentifier identifier, MetadataInfo metadataInfo) {
+ zkClient.create(getNodePath(identifier), gson.toJson(metadataInfo), false);
+
+ }
+
+ @Override
+ public void registerServiceAppMapping(String serviceKey, String application, URL url) {
+ Map<String, String> value = new HashMap<>();
+ value.put("timestamp", String.valueOf(System.currentTimeMillis()));
+ zkClient.create(toRootDir() + serviceKey + PATH_SEPARATOR + application, gson.toJson(value), false);
+ }
+
+ @Override
+ public MetadataInfo getAppMetadata(SubscriberMetadataIdentifier identifier, Map<String, String> instanceMetadata) {
+ String content = zkClient.getContent(getNodePath(identifier));
+ return gson.fromJson(content, MetadataInfo.class);
+ }
+
+ @Override
+ public Set<String> getServiceAppMapping(String serviceKey, MappingListener listener, URL url) {
+ Set<String> appNameSet = new HashSet<>();
+ appNameSet.addAll(zkClient.getChildren(toRootDir() + serviceKey));
+ return appNameSet;
+ }
}
diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
index 1315c54..21972e2 100644
--- a/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
+++ b/dubbo-registry/dubbo-registry-api/src/main/java/org/apache/dubbo/registry/client/ServiceDiscoveryRegistry.java
@@ -314,16 +314,16 @@ public class ServiceDiscoveryRegistry implements Registry {
serviceListener.setUrl(url);
listener.addServiceListener(serviceListener);
+ String protocolServiceKey = url.getServiceKey() + GROUP_CHAR_SEPARATOR + url.getParameter(PROTOCOL_KEY, DUBBO);
+ serviceListener.addListener(protocolServiceKey, listener);
+ registerServiceInstancesChangedListener(url, serviceListener);
+
serviceNames.forEach(serviceName -> {
List<ServiceInstance> serviceInstances = serviceDiscovery.getInstances(serviceName);
serviceListener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances));
});
- String protocolServiceKey = url.getServiceKey() + GROUP_CHAR_SEPARATOR + url.getParameter(PROTOCOL_KEY, DUBBO);
listener.notify(serviceListener.getUrls(protocolServiceKey));
-
- serviceListener.addListener(protocolServiceKey, listener);
- registerServiceInstancesChangedListener(url, serviceListener);
}
/**