This is an automated email from the ASF dual-hosted git repository.
songxiaosheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-samples.git
The following commit(s) were added to refs/heads/main by this push:
new 5fdd22e add mesh-router samples (#21)
5fdd22e is described below
commit 5fdd22ed0199d116720288fb6c462957b9043631
Author: heliang666s <[email protected]>
AuthorDate: Mon Dec 2 10:42:08 2024 +0800
add mesh-router samples (#21)
Co-authored-by: 何亮 <[email protected]>
---
.../case-configuration.yml | 68 +++++++++
.../case-versions.conf | 25 ++++
.../samples-spi-cluster-router-mesh/pom.xml | 156 +++++++++++++++++++++
.../dubbo/samples/governance/BasicConsumer.java | 37 +++++
.../dubbo/samples/governance/BasicProvider.java | 36 +++++
.../dubbo/samples/governance/BasicProvider2.java | 36 +++++
.../apache/dubbo/samples/governance/RuleUtil.java | 83 +++++++++++
.../dubbo/samples/governance/api/DemoService.java | 26 ++++
.../samples/governance/impl/DemoServiceImpl.java | 30 ++++
.../samples/governance/impl/DemoServiceImpl2.java | 30 ++++
.../src/main/resources/dubbo-routers-mesh-rule.yml | 51 +++++++
.../src/main/resources/log4j2.xml | 29 ++++
.../main/resources/spring/dubbo-demo-consumer.xml | 36 +++++
.../main/resources/spring/dubbo-demo-provider.xml | 43 ++++++
.../main/resources/spring/dubbo-demo-provider2.xml | 42 ++++++
.../dubbo/samples/governance/DemoServiceIT.java | 52 +++++++
pom.xml | 1 +
17 files changed, 781 insertions(+)
diff --git
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/case-configuration.yml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/case-configuration.yml
new file mode 100644
index 0000000..1f6c337
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/case-versions.conf
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/case-versions.conf
new file mode 100644
index 0000000..427d630
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/case-versions.conf
@@ -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.
+#
+
+
+# Supported component versions of the test case
+
+# Spring app
+dubbo.version=3.3.*
+spring.version=4.*, 5.*
+java.version= [>= 8]
diff --git
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/pom.xml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/pom.xml
new file mode 100644
index 0000000..d3d288a
--- /dev/null
+++ b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/pom.xml
@@ -0,0 +1,156 @@
+<?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>
+ <name>Dubbo Samples Mesh Rule Router</name>
+ <description>Dubbo Samples Mesh Rule Router</description>
+
+ <properties>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
+ <dubbo.version>3.3.2</dubbo.version>
+ <spring.version>4.3.30.RELEASE</spring.version>
+ <log4j2.version>2.20.0</log4j2.version>
+ <junit.version>4.13.1</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>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo.extensions</groupId>
+ <artifactId>dubbo-cluster-router-mesh</artifactId>
+ <version>3.3.0</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+ <artifactId>dubbo</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.dubbo</groupId>
+
<artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>${log4j2.version}</version>
+ </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>
+ </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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
new file mode 100644
index 0000000..f36c2d1
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicConsumer.java
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicProvider.java
new file mode 100644
index 0000000..033bf62
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/BasicProvider2.java
new file mode 100644
index 0000000..c6d5898
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
new file mode 100644
index 0000000..39b6f54
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/RuleUtil.java
@@ -0,0 +1,83 @@
+/*
+ * 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.out.println("rule started!");
+ 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/dubbo/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/dubbo/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/api/DemoService.java
new file mode 100644
index 0000000..bde5f6e
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl.java
new file mode 100644
index 0000000..8825f2a
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/java/org/apache/dubbo/samples/governance/impl/DemoServiceImpl2.java
new file mode 100644
index 0000000..e415108
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/dubbo-routers-mesh-rule.yml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/dubbo-routers-mesh-rule.yml
new file mode 100644
index 0000000..84eee65
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/log4j2.xml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/log4j2.xml
new file mode 100644
index 0000000..69e1321
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/log4j2.xml
@@ -0,0 +1,29 @@
+<?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.
+ -->
+<Configuration status="WARN">
+ <Appenders>
+ <Console name="Console" target="SYSTEM_OUT" follow="true">
+ <PatternLayout pattern="%style{%d{HH:mm:ss.SSS}}{Magenta}
%style{|-}{White}%highlight{%-5p} [%t] %style{%40.40c}{Cyan}:%style{%-3L}{Blue}
%style{-|}{White}
%m%n%rEx{filters(jdk.internal.reflect,java.lang.reflect,sun.reflect)}"
disableAnsi="false" charset="UTF-8"/>
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Root level="info">
+ <AppenderRef ref="Console"/>
+ </Root>
+ </Loggers>
+</Configuration>
diff --git
a/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-consumer.xml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-consumer.xml
new file mode 100644
index 0000000..009a73c
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/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
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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider.xml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider.xml
new file mode 100644
index 0000000..9945ba1
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
+ xmlns="http://www.springframework.org/schema/beans"
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:provider token="true"/>
+
+ <dubbo:protocol name="dubbo" port="${dubbo.port:-1}" heartbeat="10000"/>
+
+ <dubbo:config-center
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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider2.xml
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider2.xml
new file mode 100644
index 0000000..84fba25
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/main/resources/spring/dubbo-demo-provider2.xml
@@ -0,0 +1,42 @@
+<?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:provider token="true"/>
+
+ <dubbo:protocol name="dubbo" port="${dubbo.port:-1}" heartbeat="10000"/>
+
+ <dubbo:config-center
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/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
new file mode 100644
index 0000000..4a522d2
--- /dev/null
+++
b/6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh/src/test/java/org/apache/dubbo/samples/governance/DemoServiceIT.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.dubbo.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/pom.xml b/pom.xml
index 02884b5..df4cccf 100755
--- a/pom.xml
+++ b/pom.xml
@@ -49,6 +49,7 @@
<module>2-dubbo-spi-protocol-samples/samples-spi-protocol</module>
<module>3-dubbo-spi-registry-samples/samples-spi-registry</module>
<module>7-dubbo-spi-loadbalance-samples/samples-spi-loadbalance/</module>
+
<module>6-dubbo-spi-cluster-samples/samples-spi-cluster-router-mesh</module>
</modules>
<dependencyManagement>