1212import org .apache .http .impl .client .HttpClientBuilder ;
1313import org .apache .http .util .EntityUtils ;
1414import org .springframework .beans .factory .annotation .Autowired ;
15+ import org .springframework .beans .factory .annotation .Qualifier ;
1516import org .springframework .beans .factory .annotation .Value ;
1617import org .springframework .cloud .commons .util .InetUtils ;
1718import org .springframework .scheduling .concurrent .ThreadPoolTaskExecutor ;
3031class AController {
3132
3233 @ Autowired
33- RestTemplate restTemplate ;
34+ @ Qualifier ("loadBalancedRestTemplate" )
35+ private RestTemplate loadBalancedRestTemplate ;
36+
37+ @ Autowired
38+ @ Qualifier ("restTemplate" )
39+ private RestTemplate restTemplate ;
3440
3541 @ Autowired
3642 InetUtils inetUtils ;
3743
38- @ Reference (application = "${dubbo.application.id}" , version = "1.0 .0" )
44+ @ Reference (application = "${dubbo.application.id}" , version = "1.1 .0" )
3945 private HelloServiceB helloServiceB ;
4046
4147 @ Autowired
@@ -81,13 +87,21 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
8187 }
8288 }
8389
84- String result = restTemplate .getForObject ("http://sc-B/b" , String .class );
90+ String result = loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
8591// String result = taskExecutor.submit(() ->
8692// restTemplate.getForObject("http://sc-B/b", String.class)
8793// ).get();
8894
89- return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" + "[config=" + configValue + "]" + " -> " +
90- result ;
95+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
96+ "[config=" + configValue + "]" + " -> " + result ;
97+ }
98+
99+ @ GetMapping ("/spring_boot" )
100+ public String spring_boot (HttpServletRequest request ) {
101+ String result = restTemplate .getForObject ("http://sc-b:20002/spring_boot" , String .class );
102+
103+ return "A" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" +
104+ " -> " + result ;
91105 }
92106
93107 @ ApiOperation (value = "HTTP 全链路灰度入口" , tags = {"入口应用" })
@@ -104,7 +118,7 @@ public String aZone(HttpServletRequest request) {
104118 }
105119 }
106120 return "A" + serviceTag + "[" + currentZone + "]" + " -> " +
107- restTemplate .getForObject ("http://sc-B/b-zone" , String .class );
121+ loadBalancedRestTemplate .getForObject ("http://sc-B/b-zone" , String .class );
108122 }
109123
110124 @ ApiOperation (value = "Dubbo 全链路灰度入口" , tags = {"入口应用" })
0 commit comments