11package com .alibabacloud .mse .demo .a ;
22
3+ import com .alibabacloud .mse .demo .a .service .FeignClient ;
34import com .alibabacloud .mse .demo .b .service .HelloServiceB ;
5+ import com .alibaba .fastjson .JSON ;
46import io .swagger .annotations .Api ;
57import io .swagger .annotations .ApiOperation ;
68import io .swagger .annotations .ApiParam ;
@@ -37,6 +39,9 @@ class AController {
3739 @ Qualifier ("loadBalancedRestTemplate" )
3840 private RestTemplate loadBalancedRestTemplate ;
3941
42+ @ Autowired
43+ private FeignClient feignClient ;
44+
4045 @ Autowired
4146 @ Qualifier ("restTemplate" )
4247 private RestTemplate restTemplate ;
@@ -50,15 +55,11 @@ class AController {
5055 @ Autowired
5156 String serviceTag ;
5257
53- @ Autowired
54- ThreadPoolTaskExecutor taskExecutor ;
55-
5658 @ Value ("${custom.config.value}" )
5759 private String configValue ;
5860
5961 private String currentZone ;
6062
61-
6263 @ PostConstruct
6364 private void init () {
6465 try {
@@ -92,9 +93,48 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
9293 }
9394
9495 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" );
98138
99139 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
100140 "[config=" + configValue + "]" + " -> " + result ;
@@ -106,7 +146,7 @@ public String flow(HttpServletRequest request) throws ExecutionException, Interr
106146
107147 ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/flow" , String .class );
108148 HttpStatus status = responseEntity .getStatusCode ();
109- String result = responseEntity .getBody () + status .value ();
149+ String result = responseEntity .getBody () + " code:" + status .value ();
110150
111151 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
112152 "[config=" + configValue + "]" + " -> " + result ;
@@ -116,13 +156,13 @@ public String flow(HttpServletRequest request) throws ExecutionException, Interr
116156 @ ApiOperation (value = "测试热点规则" , tags = {"流量防护" })
117157 @ GetMapping ("/params/{hot}" )
118158 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 );
120160
121161 HttpStatus status = responseEntity .getStatusCode ();
122- String result = responseEntity .getBody () + status .value ();
162+ String result = responseEntity .getBody () + " code:" + status .value ();
123163
124164 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
125- "[config=" + configValue + "]" + " -> " + result ;
165+ "[config=" + configValue + "]" + " params:" + hot + " -> " + result ;
126166 }
127167
128168 @ ApiOperation (value = "测试隔离规则" , tags = { "流量防护" })
@@ -131,7 +171,7 @@ public String isolate(HttpServletRequest request) throws ExecutionException, Int
131171 ResponseEntity <String > responseEntity = loadBalancedRestTemplate .getForEntity ("http://sc-B/isolate" , String .class );
132172
133173 HttpStatus status = responseEntity .getStatusCode ();
134- String result = responseEntity .getBody () + status .value ();
174+ String result = responseEntity .getBody () + " code:" + status .value ();
135175
136176 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
137177 "[config=" + configValue + "]" + " -> " + result ;
@@ -146,6 +186,15 @@ public String spring_boot(HttpServletRequest request) {
146186 " -> " + result ;
147187 }
148188
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+
149198 @ ApiOperation (value = "HTTP 全链路灰度入口" , tags = {"入口应用" })
150199 @ GetMapping ("/a-zone" )
151200 public String aZone (HttpServletRequest request ) {
@@ -177,10 +226,10 @@ public String dubbo(HttpServletRequest request) {
177226 }
178227 }
179228 return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " -> " +
180- helloServiceB .hello ("A" );
229+ helloServiceB .hello (JSON . toJSONString ( request . getParameterMap ()) );
181230 }
182231
183- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
232+ @ ApiOperation (value = "Dubbo 限流测试 " , tags = {"入口应用" })
184233 @ GetMapping ("/dubbo-flow" )
185234 public String dubbo_flow (HttpServletRequest request ) {
186235 StringBuilder headerSb = new StringBuilder ();
@@ -197,7 +246,7 @@ public String dubbo_flow(HttpServletRequest request) {
197246 helloServiceB .hello ("A" );
198247 }
199248
200- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
249+ @ ApiOperation (value = "Dubbo 热点测试 " , tags = {"入口应用" })
201250 @ GetMapping ("/dubbo-params/{hot}" )
202251 public String dubbo_params (HttpServletRequest request , @ PathVariable ("hot" ) String hot ) {
203252 StringBuilder headerSb = new StringBuilder ();
@@ -210,11 +259,11 @@ public String dubbo_params(HttpServletRequest request, @PathVariable("hot") Stri
210259 headerSb .append (headerName + ":" + headerVal + "," );
211260 }
212261 }
213- return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " -> " +
262+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + " params:" + hot + " -> " +
214263 helloServiceB .hello (hot );
215264 }
216265
217- @ ApiOperation (value = "Dubbo 全链路灰度入口 " , tags = {"入口应用" })
266+ @ ApiOperation (value = "Dubbo 隔离测试 " , tags = {"入口应用" })
218267 @ GetMapping ("/dubbo-isolate" )
219268 public String dubbo_isolate (HttpServletRequest request ) {
220269 StringBuilder headerSb = new StringBuilder ();
@@ -239,6 +288,4 @@ public String swagger(@ApiParam(name = "name", value = "我是姓名", required
239288 @ ApiParam (name = "aliware-products" , value = "我是购买阿里云原生产品列表" , required = true ) List <String > aliwareProducts ) {
240289 return "hello swagger" ;
241290 }
242-
243-
244291}
0 commit comments