Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support OpenSergo traffic routing capability samples. #715

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions 4-governance/dubbo-samples-opensergo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# governance dubbo using OpenSergo Tag router
1. step1 run `BasicProvider.java`

> it will start an zookeeper and register two service with dubbo port 20880
2. step2 run `BasicProviderOtherPort.java`
> it will register another two service with dubbo port 20881
3. step3 Start OpenSergoControlPlane and apply traffic config
[First start OpenSergo control plane](https://opensergo.io/docs/quick-start/opensergo-control-plane/) , Then we publish the label routing rules through the OpenSergo control plane. We publish a TrafficRouter rule.
```YAML
kubectl apply -f - << EOF
apiVersion: traffic.opensergo.io/v1alpha1
kind: TrafficRouter
metadata:
name: governance-opensergo-traffic-provider
namespace: default
labels:
app: governance-opensergo-traffic-provider
spec:
hosts:
- governance-opensergo-traffic-provider
http:
- match:
- headers:
tag:
exact: v2
route:
- destination:
host: governance-opensergo-traffic-provider
subset: v2
- route:
- destination:
host: governance-opensergo-traffic-provider
subset: v1
EOF
```
This [TrafficRouter](https://github.com/opensergo/opensergo-specification/blob/main/specification/en/traffic-routing.md)
specifies the simplest label routing rule. Dubbo requests with the v2 header are routed to v2, and the rest of the traffic is routed to v1.

4. step4 run `BasicConsumer.java`
> it will consume service by rule defined by yml file
> * All consumer taged by `v2` come from provider in port 20881
> * All consumer taged by `v1` come from provider in port 20880
68 changes: 68 additions & 0 deletions 4-governance/dubbo-samples-opensergo/case-configuration.yml
Original file line number Diff line number Diff line change
@@ -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-tagrouter1:
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-tagrouter2:
type: app
basedir: .
mainClass: org.apache.dubbo.samples.governance.BasicProvider
systemProps:
- zookeeper.address=zookeeper
- zookeeper.port=2181
- dubbo.port=20881
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20881
checkLog: "dubbo service started"
depends_on:
- zookeeper

dubbo-samples-tagrouter-test:
type: test
basedir: .
tests:
- "**/*IT.class"
systemProps:
- zookeeper.address=zookeeper
- zookeeper.port=2181
waitPortsBeforeRun:
- zookeeper:2181
- dubbo-samples-tagrouter1:20880
- dubbo-samples-tagrouter2:20881
depends_on:
- zookeeper
- dubbo-samples-tagrouter1
- dubbo-samples-tagrouter2
25 changes: 25 additions & 0 deletions 4-governance/dubbo-samples-opensergo/case-versions.conf
Original file line number Diff line number Diff line change
@@ -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=2.7*, 3.*
spring.version=4.*, 5.*
java.version= [<= 11]
161 changes: 161 additions & 0 deletions 4-governance/dubbo-samples-opensergo/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?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-opensergo</artifactId>
<name>Dubbo Samples OpenSergo</name>
<description>Dubbo Samples OpenSergo</description>
<properties>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<dubbo.version>3.2.0-beta.3-SNAPSHOT</dubbo.version>
<dubbo-opensergo.version>1.0.0-SNAPSHOT</dubbo-opensergo.version>
<spring.version>4.3.29.RELEASE</spring.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>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-cluster-opensergo</artifactId>
<version>${dubbo-opensergo.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>io.envoyproxy.controlplane</groupId>
<artifactId>api</artifactId>
<version>1.0.36</version>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.dubbo.extensions</groupId>
<artifactId>dubbo-cluster-opensergo</artifactId>
</dependency>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
*
* 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.samples.governance.api.DemoService;
import org.apache.dubbo.samples.governance.api.DemoService2;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.apache.dubbo.common.constants.CommonConstants.TAG_KEY;
import static org.apache.dubbo.rpc.Constants.FORCE_USE_TAG;

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);
DemoService2 demoService2 = context.getBean("demoService2", DemoService2.class);

RpcContext.getContext().setAttachment("tag", "v2");
String hello = demoService.sayHello("world");
System.out.println(hello);

String hello2 = demoService2.sayHello("world again");
System.out.println(hello2);


hello = demoService.sayHello("world");
System.out.println(hello);


hello = demoService.sayHello("world");
System.out.println(hello);
hello = demoService.sayHello("world");
System.out.println(hello);
hello = demoService.sayHello("world");
System.out.println(hello);
hello = demoService.sayHello("world");
System.out.println(hello);

}
}
Loading