add mesh rule samples (#287)
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/case-configuration.yml b/dubbo-samples-governance/dubbo-samples-meshrule-router/case-configuration.yml
new file mode 100644
index 0000000..1f6c337
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/case-configuration.yml
@@ -0,0 +1,68 @@
+# 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.
+
+services:
+ zookeeper:
+ image: zookeeper:latest
+
+ dubbo-samples-mesh-router-1:
+ type: app
+ basedir: .
+ mainClass: org.apache.dubbo.samples.governance.BasicProvider
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ - dubbo.port=20880
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20880
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ dubbo-samples-mesh-router-2:
+ type: app
+ basedir: .
+ mainClass: org.apache.dubbo.samples.governance.BasicProvider2
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ - dubbo.port=20881
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ checkPorts:
+ - 20881
+ checkLog: "dubbo service started"
+ depends_on:
+ - zookeeper
+
+ dubbo-samples-mesh-router-test:
+ type: test
+ basedir: .
+ tests:
+ - "**/*IT.class"
+ systemProps:
+ - zookeeper.address=zookeeper
+ - zookeeper.port=2181
+ waitPortsBeforeRun:
+ - zookeeper:2181
+ - dubbo-samples-mesh-router-1:20880
+ - dubbo-samples-mesh-router-2:20881
+ depends_on:
+ - zookeeper
+ - dubbo-samples-mesh-router-1
+ - dubbo-samples-mesh-router-2
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/case-versions.conf b/dubbo-samples-governance/dubbo-samples-meshrule-router/case-versions.conf
new file mode 100644
index 0000000..d718a9f
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/case-versions.conf
@@ -0,0 +1,24 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.*
+spring.version=4.*, 5.*
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/pom.xml b/dubbo-samples-governance/dubbo-samples-meshrule-router/pom.xml
new file mode 100644
index 0000000..2c50828
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/pom.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <groupId>org.apache.dubbo</groupId>
+ <version>1.0-SNAPSHOT</version>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>dubbo-samples-meshrule-router</artifactId>
+ <properties>
+ <source.level>1.8</source.level>
+ <target.level>1.8</target.level>
+ <dubbo.version>3.0.0-SNAPSHOT</dubbo.version>
+ <spring.version>4.3.16.RELEASE</spring.version>
+ <junit.version>4.12</junit.version>
+ <maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-framework-bom</artifactId>
+ <version>${spring.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-bom</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <type>pom</type>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <!-- For jdk 11 above JavaEE annotation -->
+ <profile>
+ <id>javax.annotation</id>
+ <activation>
+ <jdk>[1.11,)</jdk>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <version>1.3.2</version>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${maven-compiler-plugin.version}</version>
+ <configuration>
+ <source>${source.level}</source>
+ <target>${target.level}</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <repositories>
+ <repository>
+ <id>apache.snapshots.https</id>
+ <name>Apache Development Snapshot Repository</name>
+ <url>https://repository.apache.org/content/repositories/snapshots</url>
+ <layout>default</layout>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>daily</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+</project>
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
new file mode 100644
index 0000000..a35dd04
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.samples.governance.api.DemoService;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class BasicConsumer {
+
+ public static void main(String[] args) {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-consumer.xml");
+ context.start();
+ DemoService demoService = context.getBean("demoService", DemoService.class);
+ for (int index = 0; index < 100; index++) {
+ String result = demoService.sayHello("java");
+ System.out.println(result);
+ }
+ }
+}
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
new file mode 100644
index 0000000..033bf62
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class BasicProvider {
+
+ 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-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java
new file mode 100644
index 0000000..c6d5898
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java
@@ -0,0 +1,36 @@
+/*
+ *
+ * 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.springframework.context.support.ClassPathXmlApplicationContext;
+
+import java.util.concurrent.CountDownLatch;
+
+public class BasicProvider2 {
+
+ public static void main(String[] args) throws Exception {
+ ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-demo-provider2.xml");
+ context.start();
+
+ System.out.println("dubbo service started");
+ new CountDownLatch(1).await();
+ }
+
+}
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
new file mode 100644
index 0000000..d29d3c5
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
@@ -0,0 +1,82 @@
+/*
+ * 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.common.utils.StringUtils;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.ExponentialBackoffRetry;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class RuleUtil {
+ private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");
+ private static CuratorFramework client;
+
+ public static void main(String[] args) throws Exception {
+ initClient();
+ generateRule();
+ System.in.read();
+ deleteRule();
+ }
+
+ public static void initClient() {
+ client = CuratorFrameworkFactory.newClient(zookeeperHost + ":2181", 60 * 1000, 60 * 1000,
+ new ExponentialBackoffRetry(1000, 3));
+ client.start();
+ }
+
+ public static void generateRule() {
+ try (InputStream yamlStream = RuleUtil.class.getResourceAsStream("/dubbo-routers-mesh-rule.yml")) {
+ String path = "/dubbo/config/DEFAULT_GROUP/governance-mesh-rule-router-provider.MESHAPPRULE";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, streamToString(yamlStream));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void deleteRule() throws Exception {
+ String path = "/dubbo/config/DEFAULT_GROUP/governance-mesh-rule-router-provider.MESHAPPRULE";
+ if (client.checkExists().forPath(path) == null) {
+ client.create().creatingParentsIfNeeded().forPath(path);
+ }
+ setData(path, "");
+ }
+
+ private static String streamToString(InputStream stream) throws IOException {
+ byte[] bytes = new byte[stream.available()];
+ stream.read(bytes);
+ return new String(bytes);
+ }
+
+ 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-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
new file mode 100644
index 0000000..bde5f6e
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.api;
+
+public interface DemoService {
+
+ String sayHello(String name);
+
+}
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..8825f2a
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.impl;
+
+import org.apache.dubbo.samples.governance.api.DemoService;
+
+public class DemoServiceImpl implements DemoService {
+
+ @Override
+ public String sayHello(String name) {
+ return "Hello," + name + " I'm Other Unit";
+ }
+}
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
new file mode 100644
index 0000000..e415108
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
@@ -0,0 +1,30 @@
+/*
+ *
+ * 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.impl;
+
+import org.apache.dubbo.samples.governance.api.DemoService;
+
+public class DemoServiceImpl2 implements DemoService {
+
+ @Override
+ public String sayHello(String name) {
+ return "Hello," + name + " I'm Center";
+ }
+}
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml
new file mode 100644
index 0000000..84eee65
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/dubbo-routers-mesh-rule.yml
@@ -0,0 +1,51 @@
+#
+#
+# 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.
+#
+#
+
+
+apiVersion: service.dubbo.apache.org/v1alpha1
+kind: VirtualService
+metadata: {name: demo-route}
+spec:
+ dubbo:
+ - routedetail:
+ - match:
+ - sourceLabels: {trafficLabel: xxx}
+ name: other-condition
+ route:
+ - destination: {host: demo, subset: other}
+ - name: center-match
+ route:
+ - destination: {host: demo, subset: center}
+ services:
+ - {regex: org.apache.dubbo.samples.governance.api.DemoService.*}
+ hosts: [demo]
+
+---
+
+apiVersion: service.dubbo.apache.org/v1alpha1
+kind: DestinationRule
+metadata: { name: demo-route }
+spec:
+ host: demo
+ subsets:
+ - name: all
+ - labels: { ut: CENTER }
+ name: center
+ - labels: { ut: other }
+ name: other
\ No newline at end of file
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/log4j.properties b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/log4j.properties
new file mode 100644
index 0000000..f30fda0
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/log4j.properties
@@ -0,0 +1,25 @@
+#
+#
+# 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.
+#
+#
+###set log levels###
+log4j.rootLogger=info, stdout
+###output to the console###
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.Target=System.out
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n
\ No newline at end of file
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-consumer.xml
new file mode 100644
index 0000000..20c9ac5
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/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" 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
+ 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-mesh-rule-consumer"/>
+
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+ <dubbo:config-center highest-priority="false" address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+ <dubbo:reference id="demoService" check="false" interface="org.apache.dubbo.samples.governance.api.DemoService"/>
+
+</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml
new file mode 100644
index 0000000..6d31af7
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider.xml
@@ -0,0 +1,41 @@
+<?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.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-mesh-rule-router-provider"/>
+
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+ <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"/>
+
+ <bean id="demoService" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl"/>
+ <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService">
+ <dubbo:parameter key="ut" value="other"/>
+ </dubbo:service>
+
+</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml
new file mode 100644
index 0000000..b6357dc
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/main/resources/spring/dubbo-demo-provider2.xml
@@ -0,0 +1,40 @@
+<?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.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-mesh-rule-router-provider"/>
+
+ <dubbo:registry address="zookeeper://${zookeeper.address:127.0.0.1}:2181"/>
+
+ <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"/>
+
+ <bean id="demoService2" class="org.apache.dubbo.samples.governance.impl.DemoServiceImpl2"/>
+ <dubbo:service interface="org.apache.dubbo.samples.governance.api.DemoService" ref="demoService2">
+ <dubbo:parameter key="ut" value="CENTER"/>
+ </dubbo:service>
+</beans>
diff --git a/dubbo-samples-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
new file mode 100644
index 0000000..d1bc39e
--- /dev/null
+++ b/dubbo-samples-governance/dubbo-samples-meshrule-router/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
@@ -0,0 +1,51 @@
+/*
+ * 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.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;
+
+@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 testDemoService() throws Exception {
+ for (int i = 0; i < 100; i++) {
+ Assert.assertEquals("Hello,java I'm Center", demoService.sayHello("java"));
+ }
+ }
+
+}
diff --git a/dubbo-samples-governance/pom.xml b/dubbo-samples-governance/pom.xml
index 98f7570..74e4d2a 100644
--- a/dubbo-samples-governance/pom.xml
+++ b/dubbo-samples-governance/pom.xml
@@ -33,6 +33,7 @@
<module>dubbo-samples-servicelevel-override</module>
<module>dubbo-samples-configconditionrouter</module>
<module>dubbo-samples-tagrouter</module>
+ <module>dubbo-samples-meshrule-router</module>
</modules>
<repositories>