Skip to content

Commit 6137439

Browse files
add springgateway,B and C add dubbo 2, upgrade the version to 3.0.1 (#155)
* feature:加入各种注释 * feature:加入SpringCloudGatewy、B服务和C服务增加2个dubbo注册接口、升级版本为3.0.1 * feature:修改helm版本
1 parent 2237b9c commit 6137439

File tree

47 files changed

+1110
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1110
-42
lines changed

mse-go-demo/a-server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
google.golang.org/grpc v1.40.0
7+
google.golang.org/protobuf v1.27.1
78
)
89

910
require (
@@ -12,5 +13,4 @@ require (
1213
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
1314
golang.org/x/text v0.3.0 // indirect
1415
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
15-
google.golang.org/protobuf v1.27.1 // indirect
1616
)

mse-go-demo/b-server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
google.golang.org/grpc v1.40.0
7+
google.golang.org/protobuf v1.27.1
78
)
89

910
require (
@@ -12,5 +13,4 @@ require (
1213
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
1314
golang.org/x/text v0.3.0 // indirect
1415
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
15-
google.golang.org/protobuf v1.27.1 // indirect
1616
)

mse-go-demo/c-server/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.19
44

55
require (
66
google.golang.org/grpc v1.40.0
7+
google.golang.org/protobuf v1.27.1
78
)
89

910
require (
@@ -12,5 +13,4 @@ require (
1213
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd // indirect
1314
golang.org/x/text v0.3.0 // indirect
1415
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
15-
google.golang.org/protobuf v1.27.1 // indirect
1616
)

mse-simple-demo/A/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ FROM dragonwell-registry.cn-hangzhou.cr.aliyuncs.com/dragonwell/dragonwell:8-ext
3636
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
3737

3838
COPY --from=build /app/target/A.jar /app/target/A.jar
39+
#COPY ./target/A.jar /app/target/A.jar
3940

4041
EXPOSE 20001
4142
ENTRYPOINT ["sh", "-c"]

mse-simple-demo/A/build.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/bin/sh
2+
3+
export REGISTRY=${REGISTRY}
4+
5+
export appName=spring-cloud-a
6+
export version=3.0.1
7+
28
set -e
39

410
cd "$(dirname "$0")"
511

6-
docker build --platform linux/amd64 . -t ${REGISTRY}spring-cloud-a:2.0.3
12+
docker build --platform linux/amd64 . -t ${REGISTRY}${appName}:${version}
713

814
if [ -n "${REGISTRY}" ]; then
9-
docker push ${REGISTRY}spring-cloud-a:2.0.3
10-
fi
15+
docker push ${REGISTRY}${appName}:${version}
16+
fi

mse-simple-demo/A/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.alibabacloud.mse.demo</groupId>
77
<artifactId>A</artifactId>
8-
<version>2.0.2</version>
8+
<version>${all.project.version}</version>
99
<packaging>jar</packaging>
1010

1111
<name>A</name>

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/AController.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.alibabacloud.mse.demo.a.service.FeignClientTest;
44
import com.alibabacloud.mse.demo.b.service.HelloServiceB;
55
import com.alibaba.fastjson.JSON;
6+
import com.alibabacloud.mse.demo.b.service.HelloServiceBTwo;
67
import io.swagger.annotations.Api;
78
import io.swagger.annotations.ApiOperation;
89
import io.swagger.annotations.ApiParam;
@@ -51,6 +52,9 @@ class AController {
5152
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
5253
private HelloServiceB helloServiceB;
5354

55+
@Reference(application = "${dubbo.application.id}", version = "1.2.0")
56+
private HelloServiceBTwo helloServiceBTwo;
57+
5458
@Autowired
5559
String serviceTag;
5660

@@ -68,6 +72,7 @@ private void init() {
6872
.setConnectTimeout(1000)
6973
.setSocketTimeout(1000)
7074
.build();
75+
//在阿里云中判断在哪个地区的内网服务地址,如杭州会输出cn-hangzhou-g
7176
HttpGet req = new HttpGet("http://100.100.100.200/latest/meta-data/zone-id");
7277
req.setConfig(requestConfig);
7378
HttpResponse response = client.execute(req);
@@ -81,6 +86,7 @@ private void init() {
8186
@GetMapping("/a")
8287
public String a(HttpServletRequest request) throws ExecutionException, InterruptedException {
8388
StringBuilder headerSb = new StringBuilder();
89+
//枚举创建完后无法更改
8490
Enumeration<String> enumeration = request.getHeaderNames();
8591
while (enumeration.hasMoreElements()) {
8692
String headerName = enumeration.nextElement();
@@ -90,7 +96,7 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
9096
headerSb.append(headerName + ":" + headerVal + ",");
9197
}
9298
}
93-
99+
//这是rpc调用的方式
94100
String result = loadBalancedRestTemplate.getForObject("http://sc-B/b", String.class);
95101

96102
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" +
@@ -228,6 +234,24 @@ public String dubbo(HttpServletRequest request) {
228234
helloServiceB.hello(JSON.toJSONString(request.getParameterMap()));
229235
}
230236

237+
238+
@ApiOperation(value = "Dubbo 全链路灰度入口", tags = {"入口应用"})
239+
@GetMapping("/dubbo2")
240+
public String dubbo2(HttpServletRequest request) {
241+
StringBuilder headerSb = new StringBuilder();
242+
Enumeration<String> enumeration = request.getHeaderNames();
243+
while (enumeration.hasMoreElements()) {
244+
String headerName = enumeration.nextElement();
245+
Enumeration<String> val = request.getHeaders(headerName);
246+
while (val.hasMoreElements()) {
247+
String headerVal = val.nextElement();
248+
headerSb.append(headerName + ":" + headerVal + ",");
249+
}
250+
}
251+
return "A" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " -> " +
252+
helloServiceBTwo.hello(JSON.toJSONString(request.getParameterMap()));
253+
}
254+
231255
@ApiOperation(value = "Dubbo 限流测试", tags = {"入口应用"})
232256
@GetMapping("/dubbo-flow")
233257
public String dubbo_flow(HttpServletRequest request) {

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/service/FeignClientFallback.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@Component
77
public class FeignClientFallback implements FallbackFactory<FeignClientTest> {
88

9+
910
static class FeignClientTestFallback implements FeignClientTest {
1011

1112
private final String finalMsg;
@@ -30,6 +31,7 @@ public String circuit_breaker_exception_b() {
3031
}
3132
}
3233

34+
//
3335
@Override
3436
public FeignClientTest create(Throwable throwable) {
3537
if (throwable == null) {

mse-simple-demo/A/src/main/java/com/alibabacloud/mse/demo/a/service/FeignClientTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @author yushan
1010
* @date 2023年02月21日
1111
*/
12+
//这是springcloud RPCFeignClient的调用方式
1213
@Component
1314
@FeignClient(name = "sc-B", fallbackFactory = FeignClientFallback.class)
1415
public interface FeignClientTest {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.alibabacloud.mse.demo.b.service;
2+
3+
public interface HelloServiceBTwo {
4+
String hello(String name);
5+
String slow();
6+
String exception();
7+
}

0 commit comments

Comments
 (0)