1
1
package com .alibabacloud .mse .demo .a ;
2
2
3
+ import com .alibabacloud .mse .demo .a .service .FeignClient ;
3
4
import com .alibabacloud .mse .demo .b .service .HelloServiceB ;
5
+ import com .alibaba .fastjson .JSON ;
4
6
import io .swagger .annotations .Api ;
5
7
import io .swagger .annotations .ApiOperation ;
6
8
import io .swagger .annotations .ApiParam ;
@@ -37,6 +39,9 @@ class AController {
37
39
@ Qualifier ("loadBalancedRestTemplate" )
38
40
private RestTemplate loadBalancedRestTemplate ;
39
41
42
+ @ Autowired
43
+ private FeignClient feignClient ;
44
+
40
45
@ Autowired
41
46
@ Qualifier ("restTemplate" )
42
47
private RestTemplate restTemplate ;
@@ -50,15 +55,11 @@ class AController {
50
55
@ Autowired
51
56
String serviceTag ;
52
57
53
- @ Autowired
54
- ThreadPoolTaskExecutor taskExecutor ;
55
-
56
58
@ Value ("${custom.config.value}" )
57
59
private String configValue ;
58
60
59
61
private String currentZone ;
60
62
61
-
62
63
@ PostConstruct
63
64
private void init () {
64
65
try {
@@ -92,9 +93,48 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
92
93
}
93
94
94
95
String result = loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
95
- // String result = taskExecutor.submit(() ->
96
- // restTemplate.getForObject("http://sc-B/b", String.class)
97
- // ).get();
96
+
97
+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
98
+ "[config=" + configValue + "]" + " -> " + result ;
99
+ }
100
+
101
+ @ ApiOperation (value = "HTTP 全链路灰度入口 a调用b和c" , tags = {"入口应用" })
102
+ @ GetMapping ("/a2bc" )
103
+ public String a2bc (HttpServletRequest request ) throws ExecutionException , InterruptedException {
104
+ StringBuilder headerSb = new StringBuilder ();
105
+ Enumeration <String > enumeration = request .getHeaderNames ();
106
+ while (enumeration .hasMoreElements ()) {
107
+ String headerName = enumeration .nextElement ();
108
+ Enumeration <String > val = request .getHeaders (headerName );
109
+ while (val .hasMoreElements ()) {
110
+ String headerVal = val .nextElement ();
111
+ headerSb .append (headerName + ":" + headerVal + "," );
112
+ }
113
+ }
114
+
115
+ String resultB = "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
116
+ "[config=" + configValue + "]" + " -> " + loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
117
+ String resultA = "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
118
+ "[config=" + configValue + "]" + " -> " + loadBalancedRestTemplate .getForObject ("http://sc-C/c" , String .class );
119
+
120
+ return resultA + "\n " + resultB ;
121
+ }
122
+
123
+ @ ApiOperation (value = "HTTP 全链路灰度入口 feign" , tags = {"入口应用" })
124
+ @ GetMapping ("/aByFeign" )
125
+ public String aByFeign (HttpServletRequest request ) throws ExecutionException , InterruptedException {
126
+ StringBuilder headerSb = new StringBuilder ();
127
+ Enumeration <String > enumeration = request .getHeaderNames ();
128
+ while (enumeration .hasMoreElements ()) {
129
+ String headerName = enumeration .nextElement ();
130
+ Enumeration <String > val = request .getHeaders (headerName );
131
+ while (val .hasMoreElements ()) {
132
+ String headerVal = val .nextElement ();
133
+ headerSb .append (headerName + ":" + headerVal + "," );
134
+ }
135
+ }
136
+
137
+ String result = feignClient .bByFeign ("test" );
98
138
99
139
return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
100
140
"[config=" + configValue + "]" + " -> " + result ;
@@ -106,7 +146,7 @@ public String flow(HttpServletRequest request) throws ExecutionException, Interr
106
146
107
147
ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/flow" , String .class );
108
148
HttpStatus status = responseEntity .getStatusCode ();
109
- String result = responseEntity .getBody () + status .value ();
149
+ String result = responseEntity .getBody () + " code:" + status .value ();
110
150
111
151
return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
112
152
"[config=" + configValue + "]" + " -> " + result ;
@@ -116,13 +156,13 @@ public String flow(HttpServletRequest request) throws ExecutionException, Interr
116
156
@ ApiOperation (value = "测试热点规则" , tags = {"流量防护" })
117
157
@ GetMapping ("/params/{hot}" )
118
158
public String params (HttpServletRequest request ,@ PathVariable ("hot" ) String hot ) throws ExecutionException , InterruptedException {
119
- ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/params/" + hot , String .class );
159
+ ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/params/" + hot , String .class );
120
160
121
161
HttpStatus status = responseEntity .getStatusCode ();
122
- String result = responseEntity .getBody () + status .value ();
162
+ String result = responseEntity .getBody () + " code:" + status .value ();
123
163
124
164
return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
125
- "[config=" + configValue + "]" + " -> " + result ;
165
+ "[config=" + configValue + "]" + " params:" + hot + " -> " + result ;
126
166
}
127
167
128
168
@ ApiOperation (value = "测试隔离规则" , tags = { "流量防护" })
@@ -131,7 +171,7 @@ public String isolate(HttpServletRequest request) throws ExecutionException, Int
131
171
ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/isolate" , String .class );
132
172
133
173
HttpStatus status = responseEntity .getStatusCode ();
134
- String result = responseEntity .getBody () + status .value ();
174
+ String result = responseEntity .getBody () + " code:" + status .value ();
135
175
136
176
return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
137
177
"[config=" + configValue + "]" + " -> " + result ;
@@ -146,6 +186,15 @@ public String spring_boot(HttpServletRequest request) {
146
186
" -> " + result ;
147
187
}
148
188
189
+ @ GetMapping ("/sql" )
190
+ public String sql (HttpServletRequest request ) {
191
+
192
+ String url = "http://sc-B/sql?" + request .getQueryString ();
193
+ String result = loadBalancedRestTemplate .getForObject (url , String .class );
194
+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
195
+ "[config=" + configValue + "]" + " -> " + result ;
196
+ }
197
+
149
198
@ ApiOperation (value = "HTTP 全链路灰度入口" , tags = {"入口应用" })
150
199
@ GetMapping ("/a-zone" )
151
200
public String aZone (HttpServletRequest request ) {
@@ -177,10 +226,10 @@ public String dubbo(HttpServletRequest request) {
177
226
}
178
227
}
179
228
return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " -> " +
180
- helloServiceB .hello ("A" );
229
+ helloServiceB .hello (JSON . toJSONString ( request . getParameterMap ()) );
181
230
}
182
231
183
- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
232
+ @ ApiOperation (value = "Dubbo 限流测试 " , tags = {"入口应用" })
184
233
@ GetMapping ("/dubbo-flow" )
185
234
public String dubbo_flow (HttpServletRequest request ) {
186
235
StringBuilder headerSb = new StringBuilder ();
@@ -197,7 +246,7 @@ public String dubbo_flow(HttpServletRequest request) {
197
246
helloServiceB .hello ("A" );
198
247
}
199
248
200
- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
249
+ @ ApiOperation (value = "Dubbo 热点测试 " , tags = {"入口应用" })
201
250
@ GetMapping ("/dubbo-params/{hot}" )
202
251
public String dubbo_params (HttpServletRequest request , @ PathVariable ("hot" ) String hot ) {
203
252
StringBuilder headerSb = new StringBuilder ();
@@ -210,11 +259,11 @@ public String dubbo_params(HttpServletRequest request, @PathVariable("hot") Stri
210
259
headerSb .append (headerName + ":" + headerVal + "," );
211
260
}
212
261
}
213
- return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " -> " +
262
+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " params:" + hot + " -> " +
214
263
helloServiceB .hello (hot );
215
264
}
216
265
217
- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
266
+ @ ApiOperation (value = "Dubbo 隔离测试 " , tags = {"入口应用" })
218
267
@ GetMapping ("/dubbo-isolate" )
219
268
public String dubbo_isolate (HttpServletRequest request ) {
220
269
StringBuilder headerSb = new StringBuilder ();
@@ -239,6 +288,4 @@ public String swagger(@ApiParam(name = "name", value = "我是姓名", required
239
288
@ ApiParam (name = "aliware-products" , value = "我是购买阿里云原生产品列表" , required = true ) List <String > aliwareProducts ) {
240
289
return "hello swagger" ;
241
290
}
242
-
243
-
244
291
}
0 commit comments