33import com .alibabacloud .mse .demo .a .service .FeignClientTest ;
44import com .alibabacloud .mse .demo .b .service .HelloServiceB ;
55import com .alibaba .fastjson .JSON ;
6+ import com .alibabacloud .mse .demo .b .service .HelloServiceBTwo ;
67import io .swagger .annotations .Api ;
78import io .swagger .annotations .ApiOperation ;
89import 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 ) {
0 commit comments