Add migration sample (#332)
* add migration sample
* change default register mode
* add timeout
* Add ASF license header
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-configuration.yml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-configuration.yml
new file mode 100644
index 0000000..a5c3ab1
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-configuration.yml
@@ -0,0 +1,65 @@
+# 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.
+
+timeout: 240
+
+services:
+ zookeeper:
+ image: zookeeper:latest
+
+ servicediscovery-migration-provider1:
+ type: app
+ basedir: dubbo-servicediscovery-migration-provider1
+ mainClass: org.apache.dubbo.demo.provider.Application
+ systemProps:
+ - zookeeper.address=zookeeper
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20881
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ servicediscovery-migration-provider2:
+ type: app
+ basedir: dubbo-servicediscovery-migration-provider2
+ mainClass: org.apache.dubbo.demo.provider.Application
+ systemProps:
+ - zookeeper.address=zookeeper
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20882
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ servicediscovery-migration-consumer-test:
+ type: test
+ basedir: dubbo-servicediscovery-migration-consumer
+ tests:
+ - "**/*IT.class"
+ systemProps:
+ - zookeeper.address=zookeeper
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ - servicediscovery-migration-provider1:20881
+ - servicediscovery-migration-provider2:20882
+ depends_on:
+ - zookeeper
+ - servicediscovery-migration-provider1
+ - servicediscovery-migration-provider2
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-versions.conf b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-versions.conf
new file mode 100644
index 0000000..c5a87cb
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/case-versions.conf
@@ -0,0 +1,24 @@
+#
+#
+# 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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.*
+spring.version=4.*, 5.*
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/pom.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/pom.xml
new file mode 100644
index 0000000..2ec4b40
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/pom.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.
+ -->
+<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>
+ <artifactId>dubbo-servicediscovery-migration</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-servicediscovery-migration-api</artifactId>
+
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ </properties>
+
+</project>
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/src/main/java/org/apache/dubbo/demo/DemoService.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/src/main/java/org/apache/dubbo/demo/DemoService.java
new file mode 100644
index 0000000..64672fa
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-api/src/main/java/org/apache/dubbo/demo/DemoService.java
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public interface DemoService {
+
+ String sayHello(String name);
+
+}
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/pom.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/pom.xml
new file mode 100644
index 0000000..b07283b
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/pom.xml
@@ -0,0 +1,63 @@
+<?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>
+ <artifactId>dubbo-servicediscovery-migration</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-servicediscovery-migration-consumer</artifactId>
+
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-servicediscovery-migration-api</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>
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java
new file mode 100644
index 0000000..562d3d7
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/Application.java
@@ -0,0 +1,48 @@
+/*
+ * 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.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class Application {
+ public static void main(String[] args) throws InterruptedException {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml");
+ context.start();
+
+ UpgradeUtil.writeForceInterfaceRule();
+ Thread.sleep(5000);
+
+ call(context);
+
+ UpgradeUtil.writeApplicationFirstRule(100);
+ Thread.sleep(5000);
+
+ call(context);
+
+ }
+
+ private static void call(ClassPathXmlApplicationContext context) {
+ DemoService demoServiceFromNormal = context.getBean("demoServiceFromNormal", DemoService.class);
+ System.out.println("result: " + demoServiceFromNormal.sayHello("name"));
+ DemoService demoServiceFromService = context.getBean("demoServiceFromService", DemoService.class);
+ System.out.println("result: " + demoServiceFromService.sayHello("name"));
+ DemoService demoServiceFromDual = context.getBean("demoServiceFromDual", DemoService.class);
+ System.out.println("result: " + demoServiceFromDual.sayHello("name"));
+ }
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/UpgradeUtil.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/UpgradeUtil.java
new file mode 100644
index 0000000..a09118f
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/java/org/apache/dubbo/demo/consumer/UpgradeUtil.java
@@ -0,0 +1,52 @@
+/*
+ * 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.common.config.configcenter.DynamicConfiguration;
+import org.apache.dubbo.rpc.model.ApplicationModel;
+
+public class UpgradeUtil {
+ private static final String DUBBO_SERVICEDISCOVERY_MIGRATION = "DUBBO_SERVICEDISCOVERY_MIGRATION";
+
+ public static void writeApplicationFirstRule(int proportion) {
+ String content = "step: APPLICATION_FIRST\r\n" +
+ "proportion: " + proportion;
+
+ String RULE_KEY = ApplicationModel.getName() + ".migration";
+ DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
+ configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
+ }
+
+ public static void writeForceInterfaceRule() {
+ String content = "step: FORCE_INTERFACE\r\n" +
+ "force: true";
+
+ String RULE_KEY = ApplicationModel.getName() + ".migration";
+ DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
+ configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
+ }
+
+ public static void writeForceApplicationRule() {
+ String content = "step: FORCE_APPLICATION\r\n" +
+ "force: true";
+
+ String RULE_KEY = ApplicationModel.getName() + ".migration";
+ DynamicConfiguration configuration = ApplicationModel.getEnvironment().getDynamicConfiguration().get();
+ configuration.publishConfig(RULE_KEY, DUBBO_SERVICEDISCOVERY_MIGRATION, content);
+ }
+
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/dubbo.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..8c3cb25
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/dubbo.properties
@@ -0,0 +1 @@
+dubbo.application.qos.port=33333
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/log4j.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/log4j.properties
new file mode 100644
index 0000000..2424381
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-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-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/spring/dubbo-consumer.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/spring/dubbo-consumer.xml
new file mode 100644
index 0000000..8ec9ef5
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/main/resources/spring/dubbo-consumer.xml
@@ -0,0 +1,32 @@
+<?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="dubbo-servicediscovery-migration-consumer"/>
+
+ <dubbo:registry address="zookeeper://${zookeeper.address:localhost}:${zookeeper.port:2181}"/>
+
+ <dubbo:reference id="demoServiceFromNormal" check="false" group="normal" interface="org.apache.dubbo.demo.DemoService"/>
+ <dubbo:reference id="demoServiceFromService" check="false" group="service" interface="org.apache.dubbo.demo.DemoService"/>
+ <dubbo:reference id="demoServiceFromDual" check="false" group="dual" interface="org.apache.dubbo.demo.DemoService"/>
+
+</beans>
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/DemoServiceIT.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/DemoServiceIT.java
new file mode 100644
index 0000000..70ed95f
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/DemoServiceIT.java
@@ -0,0 +1,125 @@
+/*
+ * 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.rpc.RpcException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath*:spring/dubbo-consumer.xml")
+public class DemoServiceIT {
+ @Autowired
+ @Qualifier("demoServiceFromNormal")
+ private DemoService demoServiceFromNormal;
+
+ @Autowired
+ @Qualifier("demoServiceFromService")
+ private DemoService demoServiceFromService;
+
+ @Autowired
+ @Qualifier("demoServiceFromDual")
+ private DemoService demoServiceFromDual;
+
+ @Test
+ public void test() throws InterruptedException {
+ // FORCE_INTERFACE --> APPLICATION_FIRST
+ testInterface();
+ testApplication();
+
+ // APPLICATION_FIRST --> FORCE_APPLICATION
+ testApplicationForce();
+
+ // FORCE_APPLICATION --> APPLICATION_FIRST
+ testApplication();
+
+ // APPLICATION_FIRST --> FORCE_INTERFACE
+ testInterface();
+
+ // FORCE_INTERFACE --> FORCE_APPLICATION
+ testApplicationForce();
+
+ // FORCE_APPLICATION --> FORCE_INTERFACE
+ testInterface();
+ }
+
+ public void testInterface() throws InterruptedException {
+ UpgradeUtil.writeForceInterfaceRule();
+ checkIfNotified();
+
+ Assert.assertTrue(demoServiceFromNormal.sayHello("client").contains("registry-type: normal"));
+ try {
+ demoServiceFromService.sayHello("client");
+ Assert.fail();
+ } catch (RpcException ignore) {
+
+ }
+ Assert.assertTrue(demoServiceFromDual.sayHello("client").contains("registry-type: normal"));
+ }
+
+ public void testApplication() throws InterruptedException {
+ UpgradeUtil.writeApplicationFirstRule(100);
+ checkIfNotified();
+
+ Assert.assertTrue(demoServiceFromNormal.sayHello("client").contains("registry-type: normal"));
+ Assert.assertTrue(demoServiceFromService.sayHello("client").contains("registry-type: service"));
+ Assert.assertTrue(demoServiceFromDual.sayHello("client").contains("registry-type: service"));
+
+
+ UpgradeUtil.writeApplicationFirstRule(50);
+ checkIfNotified();
+
+ int serviceCount = 0;
+ for (int i = 0; i < 100; i++) {
+ if (demoServiceFromDual.sayHello("client").contains("registry-type: service")) {
+ serviceCount += 1;
+ }
+ }
+ Assert.assertTrue(serviceCount < 100);
+ }
+
+ public void testApplicationForce() throws InterruptedException {
+ UpgradeUtil.writeForceApplicationRule();
+ checkIfNotified();
+
+ try {
+ demoServiceFromNormal.sayHello("client");
+ Assert.fail();
+ } catch (RpcException ignore) {
+
+ }
+ Assert.assertTrue(demoServiceFromService.sayHello("client").contains("registry-type: service"));
+ Assert.assertTrue(demoServiceFromDual.sayHello("client").contains("registry-type: service"));
+ }
+
+ private void checkIfNotified() throws InterruptedException {
+ for (int i = 0; i < 50; i++) {
+ if (FrameworkStatusReporterImpl.getReport().size() == 3) {
+ FrameworkStatusReporterImpl.clearReport();
+ return;
+ }
+ Thread.sleep(100);
+ }
+ }
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/FrameworkStatusReporterImpl.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/FrameworkStatusReporterImpl.java
new file mode 100644
index 0000000..40f7109
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/java/org/apache/dubbo/demo/consumer/FrameworkStatusReporterImpl.java
@@ -0,0 +1,44 @@
+/*
+ * 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.common.status.reporter.FrameworkStatusReporter;
+
+import com.google.gson.Gson;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FrameworkStatusReporterImpl implements FrameworkStatusReporter {
+ private static final Map<String, String> report = new HashMap<>();
+
+ @Override
+ public void report(String type, Object obj) {
+ if (obj instanceof String) {
+ Object group = new Gson().fromJson((String) obj, Map.class).get("group");
+ report.put((String) group, (String) obj);
+ }
+ }
+
+ public static Map<String, String> getReport() {
+ return report;
+ }
+
+ public static void clearReport() {
+ report.clear();
+ }
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/resources/META-INF.dubbo.internal/org.apache.dubbo.common.status.reporter.FrameworkStatusReporter b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/resources/META-INF.dubbo.internal/org.apache.dubbo.common.status.reporter.FrameworkStatusReporter
new file mode 100644
index 0000000..98a8d9f
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-consumer/src/test/resources/META-INF.dubbo.internal/org.apache.dubbo.common.status.reporter.FrameworkStatusReporter
@@ -0,0 +1 @@
+test = org.apache.dubbo.demo.consumer.FrameworkStatusReporterImpl
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/pom.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/pom.xml
new file mode 100644
index 0000000..f6514ff
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/pom.xml
@@ -0,0 +1,62 @@
+<?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>
+ <artifactId>dubbo-servicediscovery-migration</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-servicediscovery-migration-provider1</artifactId>
+
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-servicediscovery-migration-api</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>
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/Application.java
new file mode 100644
index 0000000..3cbf713
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Application {
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java
new file mode 100644
index 0000000..b3cb93c
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+public class DemoServiceFromDual implements DemoService {
+ private static final Logger logger = LoggerFactory.getLogger(DemoServiceFromDual.class);
+
+ @Override
+ public String sayHello(String name) {
+ logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress() + ", registry-type: normal";
+ }
+
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromNormal.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromNormal.java
new file mode 100644
index 0000000..0285204
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromNormal.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+public class DemoServiceFromNormal implements DemoService {
+ private static final Logger logger = LoggerFactory.getLogger(DemoServiceFromNormal.class);
+
+ @Override
+ public String sayHello(String name) {
+ logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress() + ", registry-type: normal";
+ }
+
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/dubbo.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..3997c19
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/dubbo.properties
@@ -0,0 +1,2 @@
+dubbo.application.qos.port=22222
+dubbo.application.register-mode=interface
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/log4j.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/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-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/spring/dubbo-provider.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/spring/dubbo-provider.xml
new file mode 100644
index 0000000..88844bb
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider1/src/main/resources/spring/dubbo-provider.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="dubbo-servicediscovery-migration-provider1"/>
+
+ <dubbo:registry id="normal" address="zookeeper://${zookeeper.address:localhost}:${zookeeper.port:2181}"/>
+
+ <dubbo:protocol name="dubbo" port="20881"/>
+
+ <bean id="demoServiceFromNormal" class="org.apache.dubbo.demo.provider.DemoServiceFromNormal"/>
+ <bean id="demoServiceFromDual" class="org.apache.dubbo.demo.provider.DemoServiceFromDual"/>
+
+ <!-- only to normal registry -->
+ <dubbo:service registry="normal" group="normal" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceFromNormal"/>
+ <!-- to both sides -->
+ <dubbo:service group="dual" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceFromDual"/>
+
+</beans>
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/pom.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/pom.xml
new file mode 100644
index 0000000..d397fd8
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/pom.xml
@@ -0,0 +1,62 @@
+<?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>
+ <artifactId>dubbo-servicediscovery-migration</artifactId>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-servicediscovery-migration-provider2</artifactId>
+
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <properties>
+ <skip_maven_deploy>true</skip_maven_deploy>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-servicediscovery-migration-api</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>
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
new file mode 100644
index 0000000..3cbf713
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/Application.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+import java.util.concurrent.CountDownLatch;
+
+public class Application {
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-provider.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java
new file mode 100644
index 0000000..60267cc
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromDual.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+public class DemoServiceFromDual implements DemoService {
+ private static final Logger logger = LoggerFactory.getLogger(DemoServiceFromDual.class);
+
+ @Override
+ public String sayHello(String name) {
+ logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress() + ", registry-type: service";
+ }
+
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromService.java b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromService.java
new file mode 100644
index 0000000..67ccd09
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/java/org/apache/dubbo/demo/provider/DemoServiceFromService.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+public class DemoServiceFromService implements DemoService {
+ private static final Logger logger = LoggerFactory.getLogger(DemoServiceFromService.class);
+
+ @Override
+ public String sayHello(String name) {
+ logger.info("Hello " + name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress()+ ", registry-type: service";
+ }
+
+}
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/dubbo.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/dubbo.properties
new file mode 100644
index 0000000..e30fde0
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/dubbo.properties
@@ -0,0 +1,2 @@
+dubbo.application.qos.port=22222
+dubbo.application.register-mode=instance
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/log4j.properties b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/log4j.properties
new file mode 100644
index 0000000..15a0900
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/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-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/spring/dubbo-provider.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/spring/dubbo-provider.xml
new file mode 100644
index 0000000..a1e5065
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/dubbo-servicediscovery-migration-provider2/src/main/resources/spring/dubbo-provider.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="dubbo-servicediscovery-migration-provider2"/>
+
+ <dubbo:registry id="service-discovery" address="zookeeper://${zookeeper.address:localhost}:${zookeeper.port:2181}?registry-type=service"/>
+
+ <dubbo:protocol name="dubbo" port="20882"/>
+
+ <bean id="demoServiceFromService" class="org.apache.dubbo.demo.provider.DemoServiceFromService"/>
+ <bean id="demoServiceFromDual" class="org.apache.dubbo.demo.provider.DemoServiceFromDual"/>
+
+ <!-- only to service discovery registry -->
+ <dubbo:service registry="service-discovery" group="service" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceFromService"/>
+ <!-- to both sides -->
+ <dubbo:service group="dual" interface="org.apache.dubbo.demo.DemoService" ref="demoServiceFromDual"/>
+
+</beans>
diff --git a/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/pom.xml b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/pom.xml
new file mode 100644
index 0000000..1faa3d3
--- /dev/null
+++ b/dubbo-samples-cloud-native/dubbo-servicediscovery-migration/pom.xml
@@ -0,0 +1,128 @@
+<?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">
+ <groupId>org.apache.dubbo</groupId>
+ <packaging>pom</packaging>
+ <version>1.0-SNAPSHOT</version>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-servicediscovery-migration</artifactId>
+
+ <modules>
+ <module>dubbo-servicediscovery-migration-api</module>
+ <module>dubbo-servicediscovery-migration-provider1</module>
+ <module>dubbo-servicediscovery-migration-provider2</module>
+ <module>dubbo-servicediscovery-migration-consumer</module>
+ </modules>
+
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>3.0.0-SNAPSHOT</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ <spring-boot-maven-plugin.version>2.1.4.RELEASE</spring-boot-maven-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-framework-bom</artifactId>
+ <version>${spring.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <!-- For jdk 11 above JavaEE annotation -->
+ <profile>
+ <id>javax.annotation</id>
+ <activation>
+ <jdk>[1.11,)</jdk>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/dubbo-samples-cloud-native/pom.xml b/dubbo-samples-cloud-native/pom.xml
index 0746e4a..66ea6eb 100644
--- a/dubbo-samples-cloud-native/pom.xml
+++ b/dubbo-samples-cloud-native/pom.xml
@@ -30,6 +30,7 @@
<module>dubbo-call-sc</module>
<module>dubbo-call-scdubbo</module>
<module>sc-call-dubbo</module>
+ <module>dubbo-servicediscovery-migration</module>
</modules>
</project>