Skip to content

Commit e215bec

Browse files
authored
add spring cloud & java chassis interoperability (#138)
1 parent 4a78672 commit e215bec

File tree

23 files changed

+1367
-0
lines changed

23 files changed

+1367
-0
lines changed
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# About Spring Cloud and Java Chassis interoperability
2+
3+
In this demo, we build a gateway using spring-cloud-gateway, a microservice `provider-java-chassis` using Java Chassis, a microservice `provider-spring-cloud` using Spring Cloud.
4+
5+
Scenario 1: User -> gateway -> provider-spring-cloud -> provider-java-chassis
6+
7+
Request:
8+
9+
`http://localhost:9090/spring-cloud/sayHello?name=World`
10+
11+
Result:
12+
13+
`"Hello from Java Chassis, World"`
14+
15+
16+
Scenario 2: User -> gateway -> provider-java-chassis -> provider-spring-cloud
17+
18+
Request:
19+
20+
`http://localhost:9090/java-chassis/sayHello?name=World`
21+
22+
Result:
23+
24+
`"Hello from Spring Cloud, World"`
25+
26+
## Using Service Center & Kie
27+
28+
Maven profile and Spring Profile using `servicecomb`.
29+
30+
## Using Nacos
31+
32+
Maven profile and Spring Profile using `nacos`.
33+
34+
>>> Notice: Nacos 2.3.0 and above is required. Because older versions of nacos will not generate instance id for Spring Cloud applications and Java Chassis interoperability needs instance id.
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.servicecomb.interoprability</groupId>
25+
<artifactId>interoprability-parent</artifactId>
26+
<version>3.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>java-chassis-3.0.x</artifactId>
30+
<packaging>pom</packaging>
31+
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
<servicecomb.version>3.0.1</servicecomb.version>
35+
</properties>
36+
37+
<dependencyManagement>
38+
<dependencies>
39+
<dependency>
40+
<groupId>org.apache.servicecomb</groupId>
41+
<artifactId>java-chassis-dependencies</artifactId>
42+
<version>${servicecomb.version}</version>
43+
<type>pom</type>
44+
<scope>import</scope>
45+
</dependency>
46+
</dependencies>
47+
</dependencyManagement>
48+
49+
<dependencies>
50+
<dependency>
51+
<groupId>org.apache.servicecomb</groupId>
52+
<artifactId>solution-basic</artifactId>
53+
</dependency>
54+
<!-- using log4j2 -->
55+
<dependency>
56+
<groupId>org.apache.logging.log4j</groupId>
57+
<artifactId>log4j-slf4j-impl</artifactId>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.apache.logging.log4j</groupId>
61+
<artifactId>log4j-api</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.apache.logging.log4j</groupId>
65+
<artifactId>log4j-core</artifactId>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.lmax</groupId>
69+
<artifactId>disruptor</artifactId>
70+
<version>3.4.4</version>
71+
</dependency>
72+
</dependencies>
73+
74+
<profiles>
75+
<profile>
76+
<id>servicecomb</id>
77+
<activation>
78+
<activeByDefault>true</activeByDefault>
79+
</activation>
80+
<dependencies>
81+
<!-- using service-center & kie -->
82+
<dependency>
83+
<groupId>org.apache.servicecomb</groupId>
84+
<artifactId>registry-service-center</artifactId>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.apache.servicecomb</groupId>
88+
<artifactId>config-kie</artifactId>
89+
</dependency>
90+
</dependencies>
91+
</profile>
92+
<profile>
93+
<id>nacos</id>
94+
<activation>
95+
<activeByDefault>false</activeByDefault>
96+
</activation>
97+
<dependencies>
98+
<!-- using nacos -->
99+
<dependency>
100+
<groupId>org.apache.servicecomb</groupId>
101+
<artifactId>registry-nacos</artifactId>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.apache.servicecomb</groupId>
105+
<artifactId>config-nacos</artifactId>
106+
</dependency>
107+
</dependencies>
108+
</profile>
109+
</profiles>
110+
111+
<modules>
112+
<module>provider</module>
113+
</modules>
114+
115+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to You under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<groupId>org.apache.servicecomb.interoprability</groupId>
25+
<artifactId>java-chassis-3.0.x</artifactId>
26+
<version>3.0-SNAPSHOT</version>
27+
</parent>
28+
29+
<artifactId>java-chassis-provider-3.0.x</artifactId>
30+
<packaging>jar</packaging>
31+
32+
<properties>
33+
</properties>
34+
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.apache.servicecomb</groupId>
38+
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.springframework.boot</groupId>
46+
<artifactId>spring-boot-maven-plugin</artifactId>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import org.springframework.boot.WebApplicationType;
21+
import org.springframework.boot.autoconfigure.SpringBootApplication;
22+
import org.springframework.boot.builder.SpringApplicationBuilder;
23+
24+
@SpringBootApplication
25+
public class ProviderApplication {
26+
public static void main(String[] args) throws Exception {
27+
try {
28+
new SpringApplicationBuilder()
29+
.web(WebApplicationType.NONE)
30+
.sources(ProviderApplication.class)
31+
.run(args);
32+
} catch (Exception e) {
33+
e.printStackTrace();
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.servicecomb.samples;
19+
20+
import org.apache.servicecomb.provider.pojo.RpcReference;
21+
import org.apache.servicecomb.provider.rest.common.RestSchema;
22+
import org.springframework.web.bind.annotation.GetMapping;
23+
import org.springframework.web.bind.annotation.RequestMapping;
24+
import org.springframework.web.bind.annotation.RequestParam;
25+
26+
@RestSchema(schemaId = "ProviderController")
27+
@RequestMapping(path = "/java-chassis")
28+
public class ProviderController {
29+
@RpcReference(schemaId = "ProviderController", microserviceName = "provider-spring-cloud")
30+
private SpringCloudService springCloudService;
31+
32+
@GetMapping("/sayHello")
33+
public String sayHello(@RequestParam("name") String name) throws Exception {
34+
return springCloudService.sayHelloInternal(name);
35+
}
36+
37+
@GetMapping("/sayHelloInternal")
38+
public String sayHelloInternal(@RequestParam("name") String name) throws Exception {
39+
return "Hello from Java Chassis, " + name;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.servicecomb.samples;
18+
19+
import org.springframework.web.bind.annotation.GetMapping;
20+
import org.springframework.web.bind.annotation.RequestMapping;
21+
import org.springframework.web.bind.annotation.RequestParam;
22+
23+
@RequestMapping("/spring-cloud")
24+
public interface SpringCloudService {
25+
@GetMapping("/sayHelloInternal")
26+
String sayHelloInternal(@RequestParam("name") String name);
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#
2+
## ---------------------------------------------------------------------------
3+
## Licensed to the Apache Software Foundation (ASF) under one or more
4+
## contributor license agreements. See the NOTICE file distributed with
5+
## this work for additional information regarding copyright ownership.
6+
## The ASF licenses this file to You under the Apache License, Version 2.0
7+
## (the "License"); you may not use this file except in compliance with
8+
## the License. You may obtain a copy of the License at
9+
##
10+
## http://www.apache.org/licenses/LICENSE-2.0
11+
##
12+
## Unless required by applicable law or agreed to in writing, software
13+
## distributed under the License is distributed on an "AS IS" BASIS,
14+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
## See the License for the specific language governing permissions and
16+
## limitations under the License.
17+
## ---------------------------------------------------------------------------
18+
servicecomb:
19+
service:
20+
application: basic-application
21+
name: provider-java-chassis
22+
environment: production
23+
version: 0.0.1
24+
rest:
25+
address: 0.0.0.0:9093
26+
27+
accesslog:
28+
enabled: true
29+
metrics:
30+
window_time: 60000
31+
invocation:
32+
latencyDistribution: 0,10,50,100,1000
33+
Consumer.invocation.slow:
34+
enabled: true
35+
msTime: 50
36+
Provider.invocation.slow:
37+
enabled: true
38+
msTime: 50
39+
publisher.defaultLog:
40+
enabled: true
41+
endpoints.client.detail.enabled: true
42+
43+
spring:
44+
profiles:
45+
active: servicecomb # 注册中心类型:servicecomb 或者 nacos
46+
47+
---
48+
spring:
49+
config:
50+
activate:
51+
on-profile: servicecomb
52+
servicecomb:
53+
# 注册发现
54+
registry:
55+
sc:
56+
address: http://localhost:30100
57+
# 动态配置
58+
kie:
59+
serverUri: http://localhost:30110
60+
61+
---
62+
spring:
63+
config:
64+
activate:
65+
on-profile: nacos
66+
servicecomb:
67+
# 注册发现
68+
registry:
69+
nacos:
70+
serverAddr: http://localhost:8848
71+
# 动态配置
72+
nacos:
73+
serverAddr: http://localhost:8848
74+

0 commit comments

Comments
 (0)