You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by li...@apache.org on 2019/07/03 07:22:37 UTC
[dubbo-samples] branch master updated: Add nacos samples (#100)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new bf8f90f Add nacos samples (#100)
bf8f90f is described below
commit bf8f90f29fbc38a1c236da18ab2abd5444541b23
Author: ken.lj <ke...@gmail.com>
AuthorDate: Wed Jul 3 15:22:33 2019 +0800
Add nacos samples (#100)
---
dubbo-samples-async/pom.xml | 1 +
.../org/apache/dubbo/samples/server/Provider1.java | 2 +-
.../org/apache/dubbo/samples/server/Provider2.java | 2 +-
.../resources/spring/dubbo-consumer.properties | 2 +-
.../resources/spring/dubbo-provider.properties | 2 +-
.../dubbo-samples-configcenter-xml/pom.xml | 2 +-
.../apache/dubbo/samples/configcenter/ZKTools.java | 2 +-
.../samples/configcenter/impl/DemoServiceImpl.java | 1 -
.../src/main/resources/config-center.properties | 2 +-
.../pom.xml | 55 ++---
.../apache/dubbo/samples/basic/BasicConsumer.java | 20 +-
.../apache/dubbo/samples/basic/BasicProvider.java | 25 +-
.../dubbo/samples/basic/EmbeddedZooKeeper.java | 255 +++++++++++++++++++++
.../dubbo/samples/basic/api/DemoService.java | 4 +-
.../dubbo/samples/basic}/impl/DemoServiceImpl.java | 9 +-
.../src/main/resources/log4j.properties | 8 +-
.../main/resources/spring/dubbo-demo-consumer.xml | 36 +++
.../main/resources/spring/dubbo-demo-provider.xml | 36 +++
.../apache/dubbo/samples/basic/DemoServiceIT.java | 41 ++++
.../dubbo-samples-applevel-override/pom.xml | 2 +-
.../apache/dubbo/samples/governance/ZKTools.java | 15 +-
.../src/main/resources/dubbo-override.yml | 2 +-
.../dubbo-samples-configconditionrouter/pom.xml | 2 +-
.../apache/dubbo/samples/governance/ZKTools.java | 11 +-
.../main/resources/spring/dubbo-demo-provider.xml | 2 +-
.../apache/dubbo/samples/governance/ZKTools.java | 18 +-
.../dubbo-samples-tagrouter/pom.xml | 2 +-
.../apache/dubbo/samples/governance/RuleUtil.java | 4 +-
.../main/resources/spring/dubbo-demo-provider.xml | 2 +-
.../dubbo-samples-nacos-conditionrouter}/pom.xml | 15 +-
.../dubbo/samples/governance/BasicConsumer.java} | 32 +--
.../dubbo/samples/governance/BasicProvider.java} | 21 +-
.../dubbo/samples/governance/api/DemoService.java} | 4 +-
.../samples/governance/api/DemoService2.java} | 4 +-
.../samples/governance}/impl/DemoServiceImpl.java | 6 +-
.../samples/governance/impl/DemoServiceImpl2.java | 12 +-
.../main/resources/dubbo-routers-condition.yml} | 14 +-
.../src/main/resources/log4j.properties | 9 +-
.../main/resources/spring/dubbo-demo-consumer.xml | 11 +-
.../main/resources/spring/dubbo-demo-provider.xml | 2 +-
.../dubbo-samples-nacos-configcenter}/pom.xml | 15 +-
.../dubbo/samples/configcenter/BasicConsumer.java | 21 +-
.../dubbo/samples/configcenter/BasicProvider.java} | 23 +-
.../samples/configcenter/EmbeddedZooKeeper.java | 250 ++++++++++++++++++++
.../samples/configcenter/api/DemoService.java} | 4 +-
.../samples/configcenter/impl/DemoServiceImpl.java | 1 -
.../src/main/resources/config-center.properties | 5 +-
.../src/main/resources/log4j.properties | 9 +-
.../resources/spring/configcenter-consumer.xml | 16 +-
.../resources/spring/configcenter-provider.xml | 31 +++
.../dubbo/samples/configcenter/DemoServiceIT.java | 41 ++++
.../dubbo-samples-nacos-override}/pom.xml | 36 ++-
.../dubbo/samples/governance/BasicConsumer.java} | 22 +-
.../dubbo/samples/governance/BasicProvider.java} | 20 +-
.../dubbo/samples/governance/api/DemoService.java} | 6 +-
.../samples/governance}/impl/DemoServiceImpl.java | 18 +-
.../src/main/resources/dubbo-override.yml | 15 +-
.../src/main/resources/log4j.properties | 9 +-
.../main/resources/spring/dubbo-demo-consumer.xml | 14 +-
.../main/resources/spring/dubbo-demo-provider.xml | 12 +-
.../dubbo-samples-nacos-registry}/pom.xml | 17 +-
.../apache/dubbo/samples/ConsumerBootstrap.java | 0
.../apache/dubbo/samples/ProviderBootstrap.java | 0
.../samples/action/GreetingServiceConsumer.java | 0
.../apache/dubbo/samples/api/GreetingService.java | 0
.../samples/impl/AnnotatedGreetingService.java | 0
.../src/main/resources/log4j.properties | 0
.../resources/spring/dubbo-consumer.properties | 0
.../resources/spring/dubbo-provider.properties | 0
.../dubbo-samples-nacos-tagrouter}/pom.xml | 17 +-
.../dubbo/samples/governance/BasicConsumer.java | 60 +++++
.../dubbo/samples/governance/BasicProvider.java} | 20 +-
.../apache/dubbo/samples/governance/RuleUtil.java | 4 +-
.../dubbo/samples/governance/api/DemoService.java} | 4 +-
.../samples/governance/api/DemoService2.java} | 4 +-
.../samples/governance}/impl/DemoServiceImpl.java | 6 +-
.../samples/governance/impl/DemoServiceImpl2.java | 12 +-
.../src/main/resources/dubbo-routers-tag.yml} | 15 +-
.../src/main/resources/log4j.properties | 9 +-
.../main/resources/spring/dubbo-demo-consumer.xml | 14 +-
.../main/resources/spring/dubbo-demo-provider.xml | 6 +-
.../dubbo/samples/governance/DemoServiceIT.java | 73 ++++++
dubbo-samples-nacos/pom.xml | 83 +++----
pom.xml | 1 +
84 files changed, 1214 insertions(+), 394 deletions(-)
diff --git a/dubbo-samples-async/pom.xml b/dubbo-samples-async/pom.xml
index 605438e..ee2f62d 100644
--- a/dubbo-samples-async/pom.xml
+++ b/dubbo-samples-async/pom.xml
@@ -31,6 +31,7 @@
<module>dubbo-samples-async-generated-future</module>
<module>dubbo-samples-async-original-future</module>
<module>dubbo-samples-async-provider</module>
+ <module>dubbo-samples-async-onerror</module>
</modules>
</project>
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
index 4ef486e..98b6cca 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider1.java
@@ -56,7 +56,7 @@ public class Provider1 {
dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
// you will need to add the configcenter address if you want to use the service governance features in 2.7,
// e.g., overrides and routers, but notice it will not be used for gathering startup configurations.
- dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
+ dubboConfigurations.put("dubbo.config-center.address", "zookeeper://127.0.0.1:2181");
return dubboConfigurations;
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
index 8f5328d..ea4c233 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/server/Provider2.java
@@ -71,7 +71,7 @@ public class Provider2 {
dubboConfigurations.put("dubbo.registry.address", "zookeeper://" + zookeeperHost + ":2181");
// you will need to add the config center address if you want to use the service governance features in 2.7,
// e.g., overrides and routers, but notice it will not be used for gathering startup configurations.
- dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://" + zookeeperHost + ":2181");
+ dubboConfigurations.put("dubbo.config-center.address", "zookeeper://" + zookeeperHost + ":2181");
return dubboConfigurations;
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-consumer.properties
index c4bcfc4..79c6442 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-consumer.properties
@@ -18,4 +18,4 @@
#
dubbo.application.name=configcenter-multi-registries-consumer
dubbo.config-center.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
-dubbo.configCenter.configFile=dubbo.properties
+dubbo.config-center.config-file=dubbo.properties
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties
index ed0967a..ac58273 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties
@@ -18,4 +18,4 @@
#
dubbo.application.name=configcenter-multi-registries-provider
dubbo.config-center.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
-dubbo.configCenter.configFile=dubbo.properties
+dubbo.config-center.config-file=dubbo.properties
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
index ecc2d60..38213a8 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
@@ -31,7 +31,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java
index ebd89b3..c9ebebd 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/ZKTools.java
@@ -64,7 +64,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/configcenter-consumer/dubbo.properties";
+ String path = "/dubbo/config/configcenter-provider/dubbo.properties";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
index a4deb00..62bd159 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
@@ -19,7 +19,6 @@
package org.apache.dubbo.samples.configcenter.impl;
-
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.samples.configcenter.api.DemoService;
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties
index 3b8c65d..ef421ba 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties
@@ -15,7 +15,7 @@
# Add the following global external properties to `/dubbo/config/dubbo/dubbo.properties`
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.protocol.port=20880
-dubbo.metadataReport.address=zookeeper://127.0.0.1:2181
+dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
dubbo.registry.simplified=true
# Optional. Add the following application(Consumer) specific external properties
# to `/dubbo/config/configcenter-consumer/dubbo.properties`
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml b/dubbo-samples-environment-keys/pom.xml
similarity index 80%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
copy to dubbo-samples-environment-keys/pom.xml
index ecc2d60..66dd476 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
+++ b/dubbo-samples-environment-keys/pom.xml
@@ -1,23 +1,20 @@
<?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.
- ~
- -->
+ 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">
@@ -26,13 +23,12 @@
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configcenter-xml</artifactId>
+ <artifactId>dubbo-samples-environment-keys</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
- <spring.version>4.3.16.RELEASE</spring.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
<jib-maven-plugin.version>1.2.0</jib-maven-plugin.version>
@@ -40,8 +36,8 @@
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
<image.name>${artifactId}:${dubbo.version}</image.name>
<dubbo.port>20880</dubbo.port>
- <zookeeper.port>2181</zookeeper.port>
- <main-class>org.apache.dubbo.samples.configcenter.BasicProvider</main-class>
+ <main-class>org.apache.dubbo.samples.basic.BasicProvider</main-class>
+ <spring-test.version>4.3.16.RELEASE</spring-test.version>
</properties>
<dependencies>
@@ -68,7 +64,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
- <version>${spring.version}</version>
+ <version>${spring-test.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -101,7 +97,7 @@
<version>${jib-maven-plugin.version}</version>
<configuration>
<from>
- <image>openjdk:8</image>
+ <image>${java-image.name}</image>
</from>
<to>
<image>${image.name}</image>
@@ -110,14 +106,11 @@
<mainClass>${main-class}</mainClass>
<ports>
<port>${dubbo.port}</port>
- <port>${zookeeper.port}</port>
+ <port>2181</port>
</ports>
<environment>
<DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
</environment>
- <jvmFlags>
- <jvmFlag>-Dzookeeper.address=${dubbo-local-address}</jvmFlag>
- </jvmFlags>
</container>
</configuration>
<executions>
@@ -141,7 +134,7 @@
<run>
<ports>
<port>${dubbo.port}:${dubbo.port}</port>
- <port>${zookeeper.port}:${zookeeper.port}</port>
+ <port>2181:2181</port>
</ports>
<wait>
<log>dubbo service started</log>
@@ -179,9 +172,6 @@
<goal>verify</goal>
</goals>
<configuration>
- <systemPropertyVariables>
- <zookeeper.address>${dubbo-local-address}</zookeeper.address>
- </systemPropertyVariables>
<includes>
<include>**/*IT.java</include>
</includes>
@@ -207,5 +197,4 @@
</plugin>
</plugins>
</build>
-
</project>
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java
similarity index 60%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
copy to dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java
index 5e7ba3d..4532160 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
+++ b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicConsumer.java
@@ -17,17 +17,19 @@
*
*/
-package org.apache.dubbo.samples.impl;
+package org.apache.dubbo.samples.basic;
-import org.apache.dubbo.config.annotation.Service;
-import org.apache.dubbo.samples.api.GreetingService;
+import org.apache.dubbo.samples.basic.api.DemoService;
-@Service
-public class AnnotatedGreetingService implements GreetingService {
+import org.springframework.context.support.ClassPathXmlApplicationContext;
- public String sayHello(String name) {
- System.out.println("greeting service received: " + name);
- return "hello, " + name;
- }
+public class BasicConsumer {
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+ context.start();
+ DemoService demoService = (DemoService) context.getBean("demoService");
+ String hello = demoService.sayHello("world");
+ System.out.println(hello);
+ }
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java
similarity index 58%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
copy to dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java
index 3c640b6..7e64a53 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
+++ b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/BasicProvider.java
@@ -17,24 +17,25 @@
*
*/
-package org.apache.dubbo.samples;
+package org.apache.dubbo.samples.basic;
-import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class ProviderBootstrap {
+public class BasicProvider {
public static void main(String[] args) throws Exception {
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
+ new EmbeddedZooKeeper(2181, false).start();
+ // wait for embedded zookeeper start completely.
+ Thread.sleep(1000);
+
+ System.setProperty("dubbo.labels", "dubbo.key1=value1; dubbo.key2=value2");
+ System.setProperty("dubbo.env.keys", "DUBBO_KEY1, DUBBO_KEY2");
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
context.start();
+
+ System.out.println("dubbo service started");
System.in.read();
}
- @Configuration
- @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.impl")
- @PropertySource("classpath:/spring/dubbo-provider.properties")
- static class ProviderConfiguration {
- }
}
diff --git a/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..969c9b8
--- /dev/null
+++ b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/EmbeddedZooKeeper.java
@@ -0,0 +1,255 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.samples.basic;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ *
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ *
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+ /**
+ * ZooKeeper client port. This will be determined dynamically upon startup.
+ */
+ private final int clientPort;
+
+ /**
+ * Whether to auto-start. Default is true.
+ */
+ private boolean autoStartup = true;
+
+ /**
+ * Lifecycle phase. Default is 0.
+ */
+ private int phase = 0;
+
+ /**
+ * Thread for running the ZooKeeper server.
+ */
+ private volatile Thread zkServerThread;
+
+ /**
+ * ZooKeeper server.
+ */
+ private volatile ZooKeeperServerMain zkServer;
+
+ /**
+ * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+ */
+ private ErrorHandler errorHandler;
+
+ private boolean daemon = true;
+
+ /**
+ * Construct an EmbeddedZooKeeper with a random port.
+ */
+ public EmbeddedZooKeeper() {
+ clientPort = SocketUtils.findAvailableTcpPort();
+ }
+
+ /**
+ * Construct an EmbeddedZooKeeper with the provided port.
+ *
+ * @param clientPort port for ZooKeeper server to bind to
+ */
+ public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+ this.clientPort = clientPort;
+ this.daemon = daemon;
+ }
+
+ /**
+ * Returns the port that clients should use to connect to this embedded server.
+ *
+ * @return dynamically determined client port
+ */
+ public int getClientPort() {
+ return this.clientPort;
+ }
+
+ /**
+ * Specify whether to start automatically. Default is true.
+ *
+ * @param autoStartup whether to start automatically
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAutoStartup() {
+ return this.autoStartup;
+ }
+
+ /**
+ * Specify the lifecycle phase for the embedded server.
+ *
+ * @param phase the lifecycle phase
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRunning() {
+ return (zkServerThread != null);
+ }
+
+ /**
+ * Start the ZooKeeper server in a background thread.
+ * <p>
+ * Register an error handler via {@link #setErrorHandler} in order to handle
+ * any exceptions thrown during startup or execution.
+ */
+ @Override
+ public synchronized void start() {
+ if (zkServerThread == null) {
+ zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+ zkServerThread.setDaemon(daemon);
+ zkServerThread.start();
+ }
+ }
+
+ /**
+ * Shutdown the ZooKeeper server.
+ */
+ @Override
+ public synchronized void stop() {
+ if (zkServerThread != null) {
+ // The shutdown method is protected...thus this hack to invoke it.
+ // This will log an exception on shutdown; see
+ // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+ try {
+ Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+ shutdown.setAccessible(true);
+ shutdown.invoke(zkServer);
+ }
+
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // It is expected that the thread will exit after
+ // the server is shutdown; this will block until
+ // the shutdown is complete.
+ try {
+ zkServerThread.join(5000);
+ zkServerThread = null;
+ }
+ catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+ // abandoning zk thread
+ zkServerThread = null;
+ }
+ }
+ }
+
+ /**
+ * Stop the server if running and invoke the callback when complete.
+ */
+ @Override
+ public void stop(Runnable callback) {
+ stop();
+ callback.run();
+ }
+
+ /**
+ * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+ * is provided, only error-level logging will occur.
+ *
+ * @param errorHandler the {@link ErrorHandler} to be invoked
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Runnable implementation that starts the ZooKeeper server.
+ */
+ private class ServerRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ try {
+ Properties properties = new Properties();
+ File file = new File(System.getProperty("java.io.tmpdir")
+ + File.separator + UUID.randomUUID());
+ file.deleteOnExit();
+ properties.setProperty("dataDir", file.getAbsolutePath());
+ properties.setProperty("clientPort", String.valueOf(clientPort));
+
+ QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+ quorumPeerConfig.parseProperties(properties);
+
+ zkServer = new ZooKeeperServerMain();
+ ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumPeerConfig);
+
+ zkServer.runFromConfig(configuration);
+ }
+ catch (Exception e) {
+ if (errorHandler != null) {
+ errorHandler.handleError(e);
+ }
+ else {
+ logger.error("Exception running embedded ZooKeeper", e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java
similarity index 92%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java
index 997ece7..f83ffaf 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/api/DemoService.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.basic.api;
-public interface GreetingService {
+public interface DemoService {
String sayHello(String name);
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java
similarity index 83%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java
index a4deb00..242fcc3 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-environment-keys/src/main/java/org/apache/dubbo/samples/basic/impl/DemoServiceImpl.java
@@ -17,11 +17,10 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.basic.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
+import org.apache.dubbo.samples.basic.api.DemoService;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -30,8 +29,8 @@ public class DemoServiceImpl implements DemoService {
@Override
public String sayHello(String name) {
- System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " +
- name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name +
+ ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-environment-keys/src/main/resources/log4j.properties
similarity index 92%
copy from dubbo-samples-nacos/src/main/resources/log4j.properties
copy to dubbo-samples-environment-keys/src/main/resources/log4j.properties
index dcb78e2..d6ecd5c 100644
--- a/dubbo-samples-nacos/src/main/resources/log4j.properties
+++ b/dubbo-samples-environment-keys/src/main/resources/log4j.properties
@@ -6,18 +6,20 @@
# 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.
-#
+#
#
+###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
diff --git a/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml
new file mode 100644
index 0000000..86f34b4
--- /dev/null
+++ b/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -0,0 +1,36 @@
+<?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.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <!-- consumer's application name, used for tracing dependency relationship (not a matching criterion),
+ don't set it same as provider -->
+ <dubbo:application name="demo-consumer"/>
+
+ <!-- use multicast registry center to discover service -->
+ <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+
+ <!-- generate proxy for the remote service, then demoService can be used in the same way as the
+ local regular interface -->
+ <dubbo:reference id="demoService" check="true" interface="org.apache.dubbo.samples.basic.api.DemoService"/>
+
+</beans>
diff --git a/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml
new file mode 100644
index 0000000..9e13902
--- /dev/null
+++ b/dubbo-samples-environment-keys/src/main/resources/spring/dubbo-demo-provider.xml
@@ -0,0 +1,36 @@
+<?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.xsd
+ http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd">
+
+ <!-- provider's application name, used for tracing dependency relationship -->
+ <dubbo:application name="demo-provider"/>
+
+ <dubbo:registry address="zookeeper://127.0.0.1:2181"/>
+
+ <!-- service implementation, as same as regular local bean -->
+ <bean id="demoService" class="org.apache.dubbo.samples.basic.impl.DemoServiceImpl"/>
+
+ <!-- declare the service interface to be exported -->
+ <dubbo:service interface="org.apache.dubbo.samples.basic.api.DemoService" ref="demoService"/>
+
+</beans>
diff --git a/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java b/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java
new file mode 100644
index 0000000..6d7d7ec
--- /dev/null
+++ b/dubbo-samples-environment-keys/src/test/java/org/apache/dubbo/samples/basic/DemoServiceIT.java
@@ -0,0 +1,41 @@
+/*
+ * 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.samples.basic;
+
+import org.apache.dubbo.samples.basic.api.DemoService;
+
+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-demo-consumer.xml")
+public class DemoServiceIT {
+ @Autowired
+ @Qualifier("demoService")
+ private DemoService service;
+
+ @Test
+ public void testGreeting() throws Exception {
+ Assert.assertTrue(service.sayHello("dubbo").startsWith("Hello dubbo"));
+ }
+}
diff --git a/dubbo-samples-governance/dubbo-samples-applevel-override/pom.xml b/dubbo-samples-governance/dubbo-samples-applevel-override/pom.xml
index ba0ce4f..8813b8b 100644
--- a/dubbo-samples-governance/dubbo-samples-applevel-override/pom.xml
+++ b/dubbo-samples-governance/dubbo-samples-applevel-override/pom.xml
@@ -31,7 +31,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
diff --git a/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java b/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
index 90d5abc..0329805 100644
--- a/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
+++ b/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.common.utils.StringUtils;
-
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -63,7 +61,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/governance-appoverride-provider/configurators";
+ String path = "/dubbo/config/dubbo/governance-appoverride-provider.configurators";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path);
}
@@ -93,7 +91,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/governance-appoverride-consumer/configurators";
+ String path = "/dubbo/config/dubbo/governance-appoverride-consumer.configurators";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path);
}
@@ -122,7 +120,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/org.apache.dubbo.samples.governance.api.DemoService/configurators";
+ String path = "/dubbo/config/dubbo/org.apache.dubbo.samples.governance.api.DemoService::.configurators";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().withMode(CreateMode.PERSISTENT).forPath(path);
}
@@ -136,11 +134,4 @@ public class ZKTools {
client.setData().forPath(path, data.getBytes());
}
- private static String pathToKey(String path) {
- if (StringUtils.isEmpty(path)) {
- return path;
- }
- return path.replace("/dubbo/config/", "").replaceAll("/", ".");
- }
-
}
diff --git a/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/resources/dubbo-override.yml b/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/resources/dubbo-override.yml
index 622d4b1..3abab95 100644
--- a/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/resources/dubbo-override.yml
+++ b/dubbo-samples-governance/dubbo-samples-applevel-override/src/main/resources/dubbo-override.yml
@@ -17,7 +17,7 @@
#
#
-# Execute on governance-appoverride-provider only and only those instances who's port is 20880 will be lifted to 1000.
+# Execute on governance-appoverride-provider only and only those instances whose port is 20880 will be lifted to 1000.
# This will take effect on all services in governance-appoverride-provider.
---
configVersion: v2.7
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml b/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
index e82713c..db77509 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
+++ b/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
@@ -31,7 +31,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java b/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
index b8cd14d..4e55a52 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
+++ b/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.common.utils.StringUtils;
-
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -54,7 +52,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/governance-conditionrouter-consumer/condition-router";
+ String path = "/dubbo/config/dubbo/governance-conditionrouter-consumer.condition-router";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -68,11 +66,4 @@ public class ZKTools {
client.setData().forPath(path, data.getBytes());
}
- private static String pathToKey(String path) {
- if (StringUtils.isEmpty(path)) {
- return path;
- }
- return path.replace("/dubbo/config/", "").replaceAll("/", ".");
- }
-
}
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
index 0c332a4..fed3425 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
@@ -29,7 +29,7 @@
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
+ <dubbo:protocol port="${dubbo.port:-1}"/>
<dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
diff --git a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
index 353f6bf..bf9c612 100644
--- a/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
+++ b/dubbo-samples-governance/dubbo-samples-servicelevel-override/src/main/java/org/apache/dubbo/samples/governance/ZKTools.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.common.utils.StringUtils;
-
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -56,7 +54,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/org.apache.dubbo.samples.governance.api.DemoService/configurators";
+ String path = "/dubbo/config/dubbo/org.apache.dubbo.samples.governance.api.DemoService::.configurators";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -84,7 +82,7 @@ public class ZKTools {
System.out.println(str);
try {
- String path = "/dubbo/config/governance-serviceoverride-consumer/configurators";
+ String path = "/dubbo/config/dubbo/governance-serviceoverride-consumer.configurators";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -96,11 +94,11 @@ public class ZKTools {
public static void cleanup() {
try {
- String path = "/dubbo/config/org.apache.dubbo.samples.governance.api.DemoService/configurators";
+ String path = "/dubbo/config/dubbo/org.apache.dubbo.samples.governance.api.DemoService::.configurators";
if (client.checkExists().forPath(path) != null) {
client.delete().forPath(path);
}
- path = "/dubbo/config/governance-serviceoverride-consumer/configurators";
+ path = "/dubbo/config/dubbo/governance-serviceoverride-consumer.configurators";
if (client.checkExists().forPath(path) != null) {
client.delete().forPath(path);
}
@@ -112,12 +110,4 @@ public class ZKTools {
private static void setData(String path, String data) throws Exception {
client.setData().forPath(path, data.getBytes());
}
-
- private static String pathToKey(String path) {
- if (StringUtils.isEmpty(path)) {
- return path;
- }
- return path.replace("/dubbo/config/", "").replaceAll("/", ".");
- }
-
}
diff --git a/dubbo-samples-governance/dubbo-samples-tagrouter/pom.xml b/dubbo-samples-governance/dubbo-samples-tagrouter/pom.xml
index cb7ebd4..73cd617 100644
--- a/dubbo-samples-governance/dubbo-samples-tagrouter/pom.xml
+++ b/dubbo-samples-governance/dubbo-samples-tagrouter/pom.xml
@@ -30,7 +30,7 @@
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
diff --git a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java b/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
index 68dffad..53d4a2d 100644
--- a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
+++ b/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
@@ -44,7 +44,7 @@ public class RuleUtil {
public static void generateRule() {
try (InputStream yamlStream = RuleUtil.class.getResourceAsStream("/dubbo-routers-tag.yml")) {
- String path = "/dubbo/config/governance-tagrouter-provider/tag-router";
+ String path = "/dubbo/config/dubbo/governance-tagrouter-provider.tag-router";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -55,7 +55,7 @@ public class RuleUtil {
}
public static void deleteRule() throws Exception {
- String path = "/dubbo/config/governance-tagrouter-provider/tag-router";
+ String path = "/dubbo/config/dubbo/governance-tagrouter-provider.tag-router";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
diff --git a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
index f0a7b10..186372a 100644
--- a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
@@ -29,7 +29,7 @@
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <dubbo:protocol name="dubbo" port="${dubbo.port:20880}" heartbeat="10000"/>
+ <dubbo:protocol name="dubbo" port="${dubbo.port:-1}" heartbeat="10000"/>
<dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
similarity index 95%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
index e82713c..9246da7 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/pom.xml
@@ -26,12 +26,12 @@
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configconditionrouter</artifactId>
+ <artifactId>dubbo-samples-nacos-conditionrouter</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -54,6 +54,17 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
similarity index 52%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
index 3c640b6..4ec8b0f 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -17,24 +17,30 @@
*
*/
-package org.apache.dubbo.samples;
+package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
+import org.apache.dubbo.samples.governance.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService2;
-public class ProviderBootstrap {
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BasicConsumer {
public static void main(String[] args) throws Exception {
- AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
context.start();
- System.in.read();
- }
- @Configuration
- @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.impl")
- @PropertySource("classpath:/spring/dubbo-provider.properties")
- static class ProviderConfiguration {
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);
+
+ while (true) {
+ String hello = demoService.sayHello("world");
+ System.out.println(hello);
+
+ String hello2 = demoService2.sayHello("world again");
+ System.out.println(hello2);
+
+ Thread.sleep(200);
+ }
}
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
similarity index 63%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
index 98266bf..a59334c 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
@@ -17,20 +17,19 @@
*
*/
-package org.apache.dubbo.samples.action;
+package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.api.GreetingService;
-import org.springframework.stereotype.Component;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+import java.util.concurrent.CountDownLatch;
- @Reference
- private GreetingService greetingService;
+public class BasicProvider {
- public String doSayHello(String name) {
- return greetingService.sayHello(name);
- }
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
+ context.start();
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
similarity index 91%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
index 997ece7..bde5f6e 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.governance.api;
-public interface GreetingService {
+public interface DemoService {
String sayHello(String name);
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
similarity index 91%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
index 997ece7..828d87c 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.governance.api;
-public interface GreetingService {
+public interface DemoService2 {
String sayHello(String name);
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
similarity index 92%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
index a4deb00..87ed741 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
@@ -17,11 +17,10 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.governance.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -34,5 +33,4 @@ public class DemoServiceImpl implements DemoService {
name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
-
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
similarity index 79%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
index a4deb00..31fa42b 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
@@ -17,22 +17,20 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.governance.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService2;
import java.text.SimpleDateFormat;
import java.util.Date;
-public class DemoServiceImpl implements DemoService {
+public class DemoServiceImpl2 implements DemoService2 {
@Override
public String sayHello(String name) {
- System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " +
- name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name +
+ ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
-
}
diff --git a/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/dubbo-routers-condition.yml
similarity index 71%
copy from dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/dubbo-routers-condition.yml
index 5cc28f7..1ee148d 100644
--- a/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/dubbo-routers-condition.yml
@@ -17,6 +17,14 @@
#
#
-dubbo.application.name=demo-consumer
-dubbo.registry.address=nacos://localhost:8848
-dubbo.consumer.timeout=3000
+---
+scope: application
+force: true
+runtime: true
+enabled: true
+priority: 2
+key: governance-conditionrouter-consumer
+conditions:
+- interface=org.apache.dubbo.samples.governance.api.DemoService&method=sayHello=>address=*:20880
+- interface=org.apache.dubbo.samples.governance.api.DemoService2&method=sayHello=>address=*:20881
+...
\ No newline at end of file
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/log4j.properties
similarity index 92%
copy from dubbo-samples-nacos/src/main/resources/log4j.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/log4j.properties
index dcb78e2..f30fda0 100644
--- a/dubbo-samples-nacos/src/main/resources/log4j.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/log4j.properties
@@ -6,18 +6,19 @@
# 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.
-#
#
-
+#
+###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
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
similarity index 76%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
index 0c332a4..9226781 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -25,17 +25,12 @@
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
- <dubbo:application name="governance-conditionrouter-provider"/>
+ <dubbo:application name="governance-conditionrouter-consumer"/>
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
-
<dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
-
- <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService2" ref="demoService2"/>
+ <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService"/>
+ <dubbo:reference id="demoService2" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService2"/>
</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
similarity index 97%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
index 0c332a4..fed3425 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-conditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
@@ -29,7 +29,7 @@
<dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
+ <dubbo:protocol port="${dubbo.port:-1}"/>
<dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/pom.xml
similarity index 94%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/pom.xml
index ecc2d60..8505897 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/pom.xml
@@ -26,12 +26,12 @@
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configcenter-xml</artifactId>
+ <artifactId>dubbo-samples-nacos-configcenter</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -53,6 +53,17 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicConsumer.java
similarity index 61%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicConsumer.java
index a4deb00..567d6e9 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicConsumer.java
@@ -17,22 +17,19 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
+package org.apache.dubbo.samples.configcenter;
-
-import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.samples.configcenter.api.DemoService;
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-public class DemoServiceImpl implements DemoService {
+public class BasicConsumer {
- @Override
- public String sayHello(String name) {
- System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " +
- name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
- return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/configcenter-consumer.xml");
+ context.start();
+ DemoService demoService = (DemoService) context.getBean("demoService");
+ String hello = demoService.sayHello("world");
+ System.out.println(hello);
}
-
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicProvider.java
similarity index 58%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicProvider.java
index 98266bf..3ab3cc6 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/BasicProvider.java
@@ -17,20 +17,23 @@
*
*/
-package org.apache.dubbo.samples.action;
+package org.apache.dubbo.samples.configcenter;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.api.GreetingService;
-import org.springframework.stereotype.Component;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+import java.util.concurrent.CountDownLatch;
- @Reference
- private GreetingService greetingService;
+public class BasicProvider {
- public String doSayHello(String name) {
- return greetingService.sayHello(name);
+ public static void main(String[] args) throws Exception {
+ new EmbeddedZooKeeper(2181, false).start();
+
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/configcenter-provider.xml");
+ context.registerShutdownHook();
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
}
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java
new file mode 100644
index 0000000..e2013f3
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/EmbeddedZooKeeper.java
@@ -0,0 +1,250 @@
+/*
+ * Copyright 2014 the original author or authors.
+ *
+ * Licensed 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.samples.configcenter;
+
+import org.apache.zookeeper.server.ServerConfig;
+import org.apache.zookeeper.server.ZooKeeperServerMain;
+import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.SmartLifecycle;
+import org.springframework.util.ErrorHandler;
+import org.springframework.util.SocketUtils;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * from: https://github.com/spring-projects/spring-xd/blob/v1.3.1.RELEASE/spring-xd-dirt/src/main/java/org/springframework/xd/dirt/zookeeper/ZooKeeperUtils.java
+ * <p>
+ * Helper class to start an embedded instance of standalone (non clustered) ZooKeeper.
+ * <p>
+ * NOTE: at least an external standalone server (if not an ensemble) are recommended, even for
+ * {@link org.springframework.xd.dirt.server.singlenode.SingleNodeApplication}
+ *
+ * @author Patrick Peralta
+ * @author Mark Fisher
+ * @author David Turanski
+ */
+public class EmbeddedZooKeeper implements SmartLifecycle {
+
+ /**
+ * Logger.
+ */
+ private static final Logger logger = LoggerFactory.getLogger(EmbeddedZooKeeper.class);
+
+ /**
+ * ZooKeeper client port. This will be determined dynamically upon startup.
+ */
+ private final int clientPort;
+
+ /**
+ * Whether to auto-start. Default is true.
+ */
+ private boolean autoStartup = true;
+
+ /**
+ * Lifecycle phase. Default is 0.
+ */
+ private int phase = 0;
+
+ /**
+ * Thread for running the ZooKeeper server.
+ */
+ private volatile Thread zkServerThread;
+
+ /**
+ * ZooKeeper server.
+ */
+ private volatile ZooKeeperServerMain zkServer;
+
+ /**
+ * {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread.
+ */
+ private ErrorHandler errorHandler;
+
+ private boolean daemon = true;
+
+ /**
+ * Construct an EmbeddedZooKeeper with a random port.
+ */
+ public EmbeddedZooKeeper() {
+ clientPort = SocketUtils.findAvailableTcpPort();
+ }
+
+ /**
+ * Construct an EmbeddedZooKeeper with the provided port.
+ *
+ * @param clientPort port for ZooKeeper server to bind to
+ */
+ public EmbeddedZooKeeper(int clientPort, boolean daemon) {
+ this.clientPort = clientPort;
+ this.daemon = daemon;
+ }
+
+ /**
+ * Returns the port that clients should use to connect to this embedded server.
+ *
+ * @return dynamically determined client port
+ */
+ public int getClientPort() {
+ return this.clientPort;
+ }
+
+ /**
+ * Specify whether to start automatically. Default is true.
+ *
+ * @param autoStartup whether to start automatically
+ */
+ public void setAutoStartup(boolean autoStartup) {
+ this.autoStartup = autoStartup;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isAutoStartup() {
+ return this.autoStartup;
+ }
+
+ /**
+ * Specify the lifecycle phase for the embedded server.
+ *
+ * @param phase the lifecycle phase
+ */
+ public void setPhase(int phase) {
+ this.phase = phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getPhase() {
+ return this.phase;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean isRunning() {
+ return (zkServerThread != null);
+ }
+
+ /**
+ * Start the ZooKeeper server in a background thread.
+ * <p>
+ * Register an error handler via {@link #setErrorHandler} in order to handle
+ * any exceptions thrown during startup or execution.
+ */
+ @Override
+ public synchronized void start() {
+ if (zkServerThread == null) {
+ zkServerThread = new Thread(new ServerRunnable(), "ZooKeeper Server Starter");
+ zkServerThread.setDaemon(daemon);
+ zkServerThread.start();
+ }
+ }
+
+ /**
+ * Shutdown the ZooKeeper server.
+ */
+ @Override
+ public synchronized void stop() {
+ if (zkServerThread != null) {
+ // The shutdown method is protected...thus this hack to invoke it.
+ // This will log an exception on shutdown; see
+ // https://issues.apache.org/jira/browse/ZOOKEEPER-1873 for details.
+ try {
+ Method shutdown = ZooKeeperServerMain.class.getDeclaredMethod("shutdown");
+ shutdown.setAccessible(true);
+ shutdown.invoke(zkServer);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ // It is expected that the thread will exit after
+ // the server is shutdown; this will block until
+ // the shutdown is complete.
+ try {
+ zkServerThread.join(5000);
+ zkServerThread = null;
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ logger.warn("Interrupted while waiting for embedded ZooKeeper to exit");
+ // abandoning zk thread
+ zkServerThread = null;
+ }
+ }
+ }
+
+ /**
+ * Stop the server if running and invoke the callback when complete.
+ */
+ @Override
+ public void stop(Runnable callback) {
+ stop();
+ callback.run();
+ }
+
+ /**
+ * Provide an {@link ErrorHandler} to be invoked if an Exception is thrown from the ZooKeeper server thread. If none
+ * is provided, only error-level logging will occur.
+ *
+ * @param errorHandler the {@link ErrorHandler} to be invoked
+ */
+ public void setErrorHandler(ErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * Runnable implementation that starts the ZooKeeper server.
+ */
+ private class ServerRunnable implements Runnable {
+
+ @Override
+ public void run() {
+ try {
+ Properties properties = new Properties();
+ File file = new File(System.getProperty("java.io.tmpdir")
+ + File.separator + UUID.randomUUID());
+ file.deleteOnExit();
+ properties.setProperty("dataDir", file.getAbsolutePath());
+ properties.setProperty("clientPort", String.valueOf(clientPort));
+
+ QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
+ quorumPeerConfig.parseProperties(properties);
+
+ zkServer = new ZooKeeperServerMain();
+ ServerConfig configuration = new ServerConfig();
+ configuration.readFrom(quorumPeerConfig);
+
+ zkServer.runFromConfig(configuration);
+ } catch (Exception e) {
+ if (errorHandler != null) {
+ errorHandler.handleError(e);
+ } else {
+ logger.error("Exception running embedded ZooKeeper", e);
+ }
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.java
similarity index 91%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.java
index 997ece7..b42cbc5 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/api/DemoService.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.configcenter.api;
-public interface GreetingService {
+public interface DemoService {
String sayHello(String name);
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
similarity index 99%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
index a4deb00..62bd159 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
@@ -19,7 +19,6 @@
package org.apache.dubbo.samples.configcenter.impl;
-
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.samples.configcenter.api.DemoService;
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/config-center.properties
similarity index 88%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/config-center.properties
index 3b8c65d..6230f4a 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/resources/config-center.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/config-center.properties
@@ -13,9 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Add the following global external properties to `/dubbo/config/dubbo/dubbo.properties`
-dubbo.registry.address=zookeeper://127.0.0.1:2181
-dubbo.protocol.port=20880
-dubbo.metadataReport.address=zookeeper://127.0.0.1:2181
+dubbo.registry.address=nacos://127.0.0.1:8848
+dubbo.protocol.port=-1
dubbo.registry.simplified=true
# Optional. Add the following application(Consumer) specific external properties
# to `/dubbo/config/configcenter-consumer/dubbo.properties`
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/log4j.properties
similarity index 92%
copy from dubbo-samples-nacos/src/main/resources/log4j.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/log4j.properties
index dcb78e2..f30fda0 100644
--- a/dubbo-samples-nacos/src/main/resources/log4j.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/log4j.properties
@@ -6,18 +6,19 @@
# 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.
-#
#
-
+#
+###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
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-consumer.xml
similarity index 65%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-consumer.xml
index 0c332a4..cb13e9d 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-consumer.xml
@@ -21,21 +21,15 @@
<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" xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
- <context:property-placeholder/>
-
- <dubbo:application name="governance-conditionrouter-provider"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <context:property-placeholder/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
+ <dubbo:application name="configcenter-consumer"/>
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center highest-priority="false" address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
+ <dubbo:reference id="demoService" interface="org.apache.dubbo.samples.configcenter.api.DemoService"/>
- <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService2" ref="demoService2"/>
</beans>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-provider.xml
new file mode 100644
index 0000000..691af59
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/main/resources/spring/configcenter-provider.xml
@@ -0,0 +1,31 @@
+<?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" xmlns:context="http://www.springframework.org/schema/context"
+ 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 http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
+
+ <context:property-placeholder/>
+ <dubbo:application name="configcenter-provider"/>
+ <dubbo:config-center address="nacos://${nacos.address:127.0.0.1}:8848"/>
+
+ <bean id="demoService" class="org.apache.dubbo.samples.configcenter.impl.DemoServiceImpl"/>
+ <dubbo:service interface="org.apache.dubbo.samples.configcenter.api.DemoService" ref="demoService"/>
+</beans>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/test/java/org/apache/dubbo/samples/configcenter/DemoServiceIT.java b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/test/java/org/apache/dubbo/samples/configcenter/DemoServiceIT.java
new file mode 100644
index 0000000..ccaf83f
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-configcenter/src/test/java/org/apache/dubbo/samples/configcenter/DemoServiceIT.java
@@ -0,0 +1,41 @@
+/*
+ * 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.samples.configcenter;
+
+import org.apache.dubbo.samples.configcenter.api.DemoService;
+
+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/configcenter-consumer.xml")
+public class DemoServiceIT {
+ @Autowired
+ @Qualifier("demoService")
+ private DemoService demoService;
+
+ @Test
+ public void test() throws Exception {
+ Assert.assertTrue(demoService.sayHello("world").startsWith("Hello world"));
+ }
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-override/pom.xml
similarity index 89%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/pom.xml
index ecc2d60..2a5ddba 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/pom.xml
@@ -18,20 +18,20 @@
~
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0"
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>
<version>1.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configcenter-xml</artifactId>
+ <artifactId>dubbo-samples-nacos-override</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -41,7 +41,7 @@
<image.name>${artifactId}:${dubbo.version}</image.name>
<dubbo.port>20880</dubbo.port>
<zookeeper.port>2181</zookeeper.port>
- <main-class>org.apache.dubbo.samples.configcenter.BasicProvider</main-class>
+ <main-class>org.apache.dubbo.samples.governance.BasicProvider</main-class>
</properties>
<dependencies>
@@ -53,6 +53,18 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
@@ -108,10 +120,6 @@
</to>
<container>
<mainClass>${main-class}</mainClass>
- <ports>
- <port>${dubbo.port}</port>
- <port>${zookeeper.port}</port>
- </ports>
<environment>
<DUBBO_IP_TO_REGISTRY>${dubbo-local-address}</DUBBO_IP_TO_REGISTRY>
</environment>
@@ -137,11 +145,18 @@
<configuration>
<images>
<image>
+ <name>zookeeper:latest</name>
+ <run>
+ <ports>
+ <port>${zookeeper.port}:${zookeeper.port}</port>
+ </ports>
+ </run>
+ </image>
+ <image>
<name>${image.name}</name>
<run>
<ports>
<port>${dubbo.port}:${dubbo.port}</port>
- <port>${zookeeper.port}:${zookeeper.port}</port>
</ports>
<wait>
<log>dubbo service started</log>
@@ -207,5 +222,4 @@
</plugin>
</plugins>
</build>
-
</project>
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
similarity index 59%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
index 98266bf..d922f93 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -17,20 +17,20 @@
*
*/
-package org.apache.dubbo.samples.action;
+package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.api.GreetingService;
-import org.springframework.stereotype.Component;
+import org.apache.dubbo.samples.governance.api.DemoService;
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+import org.springframework.context.support.ClassPathXmlApplicationContext;
- @Reference
- private GreetingService greetingService;
+public class BasicConsumer {
- public String doSayHello(String name) {
- return greetingService.sayHello(name);
- }
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+ context.start();
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ String hello = demoService.sayHello("world", 5000);
+ System.out.println(hello);
+ }
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
similarity index 63%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
index 98266bf..033bf62 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
@@ -17,20 +17,20 @@
*
*/
-package org.apache.dubbo.samples.action;
+package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.api.GreetingService;
-import org.springframework.stereotype.Component;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+import java.util.concurrent.CountDownLatch;
- @Reference
- private GreetingService greetingService;
+public class BasicProvider {
- public String doSayHello(String name) {
- return greetingService.sayHello(name);
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
similarity index 86%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
index 997ece7..957c601 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
@@ -17,10 +17,10 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.governance.api;
-public interface GreetingService {
+public interface DemoService {
- String sayHello(String name);
+ String sayHello(String name, long millis);
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
similarity index 71%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
index a4deb00..8be2656 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
@@ -17,22 +17,20 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.governance.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
-
-import java.text.SimpleDateFormat;
-import java.util.Date;
+import org.apache.dubbo.samples.governance.api.DemoService;
public class DemoServiceImpl implements DemoService {
@Override
- public String sayHello(String name) {
- System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " +
- name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ public String sayHello(String name, long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
-
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/dubbo-override.yml
similarity index 71%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/dubbo-override.yml
index ed0967a..2d1b0f0 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-multi-registries/src/main/resources/spring/dubbo-provider.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/dubbo-override.yml
@@ -16,6 +16,15 @@
# limitations under the License.
#
#
-dubbo.application.name=configcenter-multi-registries-provider
-dubbo.config-center.address=zookeeper://${zookeeper.address:127.0.0.1}:2181
-dubbo.configCenter.configFile=dubbo.properties
+# All Consumers that consume the service org.apache.dubbo.samples.governance.api.DemoService will increase the timeout value to 6000
+---
+configVersion: v2.7
+scope: service
+key: org.apache.dubbo.samples.governance.api.DemoService
+enabled: true
+configs:
+- addresses: [0.0.0.0]
+ side: consumer
+ parameters:
+ timeout: 6000
+...
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/log4j.properties
similarity index 92%
copy from dubbo-samples-nacos/src/main/resources/log4j.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/log4j.properties
index dcb78e2..f30fda0 100644
--- a/dubbo-samples-nacos/src/main/resources/log4j.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/log4j.properties
@@ -6,18 +6,19 @@
# 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.
-#
#
-
+#
+###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
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-consumer.xml
similarity index 68%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-consumer.xml
index 0c332a4..e871db4 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -25,17 +25,11 @@
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
- <dubbo:application name="governance-conditionrouter-provider"/>
+ <dubbo:application name="governance-serviceoverride-consumer"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
+ <dubbo:reference timeout="1000" id="demoService" check="false"
+ interface="org.apache.dubbo.samples.governance.api.DemoService"/>
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
-
- <bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
-
- <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService2" ref="demoService2"/>
</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-provider.xml
similarity index 77%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-provider.xml
index 0c332a4..fa3166b 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-override/src/main/resources/spring/dubbo-demo-provider.xml
@@ -25,17 +25,13 @@
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
- <dubbo:application name="governance-conditionrouter-provider"/>
+ <dubbo:application name="governance-serviceoverride-provider"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
-
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:protocol name="dubbo" port="-1"/>
<bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
- <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService2" ref="demoService2"/>
+ <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
similarity index 94%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
index e82713c..7e18e8c 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-registry/pom.xml
@@ -26,12 +26,12 @@
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configconditionrouter</artifactId>
+ <artifactId>dubbo-samples-nacos-registry</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -42,7 +42,7 @@
<dubbo.port.1>20880</dubbo.port.1>
<dubbo.port.2>20881</dubbo.port.2>
<zookeeper.port>2181</zookeeper.port>
- <main-class>org.apache.dubbo.samples.governance.BasicProvider</main-class>
+ <main-class>org.apache.dubbo.samples.ProviderBootstrap</main-class>
</properties>
<dependencies>
@@ -54,6 +54,17 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
similarity index 100%
rename from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
rename to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
similarity index 100%
rename from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
rename to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
similarity index 100%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
similarity index 100%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
similarity index 100%
rename from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
rename to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/log4j.properties
similarity index 100%
copy from dubbo-samples-nacos/src/main/resources/log4j.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/log4j.properties
diff --git a/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-consumer.properties
similarity index 100%
copy from dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
copy to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-consumer.properties
diff --git a/dubbo-samples-nacos/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties
similarity index 100%
rename from dubbo-samples-nacos/src/main/resources/spring/dubbo-provider.properties
rename to dubbo-samples-nacos/dubbo-samples-nacos-registry/src/main/resources/spring/dubbo-provider.properties
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/pom.xml
similarity index 95%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/pom.xml
index e82713c..e2e1ada 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/pom.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/pom.xml
@@ -26,12 +26,11 @@
<modelVersion>4.0.0</modelVersion>
- <artifactId>dubbo-samples-configconditionrouter</artifactId>
-
+ <artifactId>dubbo-samples-nacos-tagrouter</artifactId>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
+ <dubbo.version>2.7.3-SNAPSHOT</dubbo.version>
<spring.version>4.3.16.RELEASE</spring.version>
<junit.version>4.12</junit.version>
<docker-maven-plugin.version>0.30.0</docker-maven-plugin.version>
@@ -54,6 +53,18 @@
<dependency>
<groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-configcenter-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-registry-nacos</artifactId>
+ <version>${dubbo.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
new file mode 100644
index 0000000..09f433d
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -0,0 +1,60 @@
+/*
+ *
+ * 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.samples.governance;
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.cluster.Constants;
+import org.apache.dubbo.samples.governance.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService2;
+
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;
+
+public class BasicConsumer {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+ context.start();
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);
+
+ while (true) {
+ try {
+ RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
+ String hello = demoService.sayHello("world");
+ System.out.println(hello);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
+ RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
+ String hello2 = demoService2.sayHello("world again");
+ System.out.println(hello2);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Thread.sleep(1000);
+ }
+ }
+}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
similarity index 63%
rename from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
rename to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
index 98266bf..033bf62 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
@@ -17,20 +17,20 @@
*
*/
-package org.apache.dubbo.samples.action;
+package org.apache.dubbo.samples.governance;
-import org.apache.dubbo.config.annotation.Reference;
-import org.apache.dubbo.samples.api.GreetingService;
-import org.springframework.stereotype.Component;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
-@Component("annotatedConsumer")
-public class GreetingServiceConsumer {
+import java.util.concurrent.CountDownLatch;
- @Reference
- private GreetingService greetingService;
+public class BasicProvider {
- public String doSayHello(String name) {
- return greetingService.sayHello(name);
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
}
}
diff --git a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
similarity index 94%
copy from dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
index 68dffad..53d4a2d 100644
--- a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
@@ -44,7 +44,7 @@ public class RuleUtil {
public static void generateRule() {
try (InputStream yamlStream = RuleUtil.class.getResourceAsStream("/dubbo-routers-tag.yml")) {
- String path = "/dubbo/config/governance-tagrouter-provider/tag-router";
+ String path = "/dubbo/config/dubbo/governance-tagrouter-provider.tag-router";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
@@ -55,7 +55,7 @@ public class RuleUtil {
}
public static void deleteRule() throws Exception {
- String path = "/dubbo/config/governance-tagrouter-provider/tag-router";
+ String path = "/dubbo/config/dubbo/governance-tagrouter-provider.tag-router";
if (client.checkExists().forPath(path) == null) {
client.create().creatingParentsIfNeeded().forPath(path);
}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
similarity index 91%
copy from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
index 997ece7..bde5f6e 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.governance.api;
-public interface GreetingService {
+public interface DemoService {
String sayHello(String name);
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
similarity index 91%
rename from dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
rename to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
index 997ece7..828d87c 100644
--- a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/api/DemoService2.java
@@ -17,9 +17,9 @@
*
*/
-package org.apache.dubbo.samples.api;
+package org.apache.dubbo.samples.governance.api;
-public interface GreetingService {
+public interface DemoService2 {
String sayHello(String name);
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
similarity index 92%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
index a4deb00..87ed741 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
@@ -17,11 +17,10 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.governance.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -34,5 +33,4 @@ public class DemoServiceImpl implements DemoService {
name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
-
}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
similarity index 79%
copy from dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
index a4deb00..31fa42b 100644
--- a/dubbo-samples-configcenter/dubbo-samples-configcenter-xml/src/main/java/org/apache/dubbo/samples/configcenter/impl/DemoServiceImpl.java
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
@@ -17,22 +17,20 @@
*
*/
-package org.apache.dubbo.samples.configcenter.impl;
-
+package org.apache.dubbo.samples.governance.impl;
import org.apache.dubbo.rpc.RpcContext;
-import org.apache.dubbo.samples.configcenter.api.DemoService;
+import org.apache.dubbo.samples.governance.api.DemoService2;
import java.text.SimpleDateFormat;
import java.util.Date;
-public class DemoServiceImpl implements DemoService {
+public class DemoServiceImpl2 implements DemoService2 {
@Override
public String sayHello(String name) {
- System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " +
- name + ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
+ System.out.println("[" + new SimpleDateFormat("HH:mm:ss").format(new Date()) + "] Hello " + name +
+ ", request from consumer: " + RpcContext.getContext().getRemoteAddress());
return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
}
-
}
diff --git a/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/dubbo-routers-tag.yml
similarity index 81%
rename from dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
rename to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/dubbo-routers-tag.yml
index 5cc28f7..89a01f9 100644
--- a/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/dubbo-routers-tag.yml
@@ -17,6 +17,15 @@
#
#
-dubbo.application.name=demo-consumer
-dubbo.registry.address=nacos://localhost:8848
-dubbo.consumer.timeout=3000
+---
+force: false
+runtime: true
+enabled: true
+priority: 1
+key: governance-tagrouter-provider
+tags:
+- name: tag1
+ addresses: ["*.*.*.*:20881"]
+- name: tag2
+ addresses: ["*.*.*.*:20880"]
+...
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/log4j.properties
similarity index 92%
rename from dubbo-samples-nacos/src/main/resources/log4j.properties
rename to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/log4j.properties
index dcb78e2..f30fda0 100644
--- a/dubbo-samples-nacos/src/main/resources/log4j.properties
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/log4j.properties
@@ -6,18 +6,19 @@
# 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.
-#
#
-
+#
+###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
diff --git a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-consumer.xml
similarity index 68%
copy from dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-consumer.xml
index 0c332a4..c18c885 100644
--- a/dubbo-samples-governance/dubbo-samples-configconditionrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-consumer.xml
@@ -25,17 +25,11 @@
http://dubbo.apache.org/schema/dubbo http://dubbo.apache.org/schema/dubbo/dubbo.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder/>
- <dubbo:application name="governance-conditionrouter-provider"/>
+ <dubbo:application name="governance-tagrouter-consumer"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center highest-priority="true" address="nacos://${nacos.address:127.0.0.1}:8848"/>
- <dubbo:protocol port="${dubbo.port:20880}"/>
+ <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService"/>
+ <dubbo:reference id="demoService2" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService2"/>
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
-
- <bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
-
- <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
- <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService2" ref="demoService2"/>
</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
similarity index 87%
copy from dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
copy to dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
index f0a7b10..df375b1 100644
--- a/dubbo-samples-governance/dubbo-samples-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/main/resources/spring/dubbo-demo-provider.xml
@@ -27,11 +27,9 @@
<dubbo:application name="governance-tagrouter-provider"/>
- <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:protocol name="dubbo" port="${dubbo.port:-1}" heartbeat="10000"/>
- <dubbo:protocol name="dubbo" port="${dubbo.port:20880}" heartbeat="10000"/>
-
- <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+ <dubbo:config-center highest-priority="true" address="nacos://${nacos.address:127.0.0.1}:8848"/>
<bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
<dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService"/>
diff --git a/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
new file mode 100644
index 0000000..ff66e5e
--- /dev/null
+++ b/dubbo-samples-nacos/dubbo-samples-nacos-tagrouter/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
@@ -0,0 +1,73 @@
+/*
+ * 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.samples.governance;
+
+import org.apache.dubbo.rpc.RpcContext;
+import org.apache.dubbo.rpc.RpcException;
+import org.apache.dubbo.rpc.cluster.Constants;
+import org.apache.dubbo.samples.governance.api.DemoService;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+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;
+
+import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = {"classpath:/spring/dubbo-demo-consumer.xml"})
+public class DemoServiceIT {
+ @Autowired
+ @Qualifier("demoService")
+ private DemoService demoService;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ RuleUtil.initClient();
+ RuleUtil.generateRule();
+ Thread.sleep(1000);
+ }
+
+ @Test
+ public void testDemoService1() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
+ RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag1");
+ Assert.assertTrue(demoService.sayHello("world").contains("20881"));
+ }
+ }
+
+ @Test
+ public void testDemoService2() throws Exception {
+ for (int i = 0; i < 10; i++) {
+ RpcContext.getContext().setAttachment(FORCE_USE_TAG, "true");
+ RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag2");
+ Assert.assertTrue(demoService.sayHello("world").contains("20880"));
+ }
+ }
+
+ @Test(expected = RpcException.class)
+ public void testDemoService3() throws Exception {
+ RpcContext.getContext().setAttachment(Constants.TAG_KEY, "tag3");
+ demoService.sayHello("world");
+ }
+}
diff --git a/dubbo-samples-nacos/pom.xml b/dubbo-samples-nacos/pom.xml
index 5c26848..cad31c3 100644
--- a/dubbo-samples-nacos/pom.xml
+++ b/dubbo-samples-nacos/pom.xml
@@ -1,60 +1,39 @@
<?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-samples-all</artifactId>
- <groupId>org.apache.dubbo</groupId>
- <version>1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
<artifactId>dubbo-samples-nacos</artifactId>
- <properties>
- <source.level>1.8</source.level>
- <target.level>1.8</target.level>
- <dubbo.version>2.7.2</dubbo.version>
- </properties>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo-dependencies-bom</artifactId>
- <version>${dubbo.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>${dubbo.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.alibaba.nacos</groupId>
- <artifactId>nacos-client</artifactId>
- </dependency>
- </dependencies>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.7.0</version>
- <configuration>
- <source>${source.level}</source>
- <target>${target.level}</target>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
+ <modules>
+ <module>dubbo-samples-nacos-override</module>
+ <module>dubbo-samples-nacos-conditionrouter</module>
+ <module>dubbo-samples-nacos-configcenter</module>
+ <module>dubbo-samples-nacos-tagrouter</module>
+ <module>dubbo-samples-nacos-registry</module>
+ </modules>
-</project>
\ No newline at end of file
+</project>
diff --git a/pom.xml b/pom.xml
index 7173797..c8882af 100644
--- a/pom.xml
+++ b/pom.xml
@@ -72,6 +72,7 @@
<module>dubbo-samples-edas</module>
<module>dubbo-samples-nacos</module>
<module>dubbo-samples-metrics</module>
+ <module>dubbo-samples-environment-keys</module>
</modules>
<properties>
<!-- Test libs -->
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org