12
12
import org .apache .http .impl .client .HttpClientBuilder ;
13
13
import org .apache .http .util .EntityUtils ;
14
14
import org .springframework .beans .factory .annotation .Autowired ;
15
+ import org .springframework .beans .factory .annotation .Qualifier ;
15
16
import org .springframework .beans .factory .annotation .Value ;
16
17
import org .springframework .cloud .commons .util .InetUtils ;
17
18
import org .springframework .scheduling .concurrent .ThreadPoolTaskExecutor ;
30
31
class AController {
31
32
32
33
@ Autowired
33
- RestTemplate restTemplate ;
34
+ @ Qualifier ("loadBalancedRestTemplate" )
35
+ private RestTemplate loadBalancedRestTemplate ;
36
+
37
+ @ Autowired
38
+ @ Qualifier ("restTemplate" )
39
+ private RestTemplate restTemplate ;
34
40
35
41
@ Autowired
36
42
InetUtils inetUtils ;
37
43
38
- @ Reference (application = "${dubbo.application.id}" , version = "1.0 .0" )
44
+ @ Reference (application = "${dubbo.application.id}" , version = "1.1 .0" )
39
45
private HelloServiceB helloServiceB ;
40
46
41
47
@ Autowired
@@ -81,13 +87,21 @@ public String a(HttpServletRequest request) throws ExecutionException, Interrupt
81
87
}
82
88
}
83
89
84
- String result = restTemplate .getForObject ("http://sc-B/b" , String .class );
90
+ String result = loadBalancedRestTemplate .getForObject ("http://sc-B/b" , String .class );
85
91
// String result = taskExecutor.submit(() ->
86
92
// restTemplate.getForObject("http://sc-B/b", String.class)
87
93
// ).get();
88
94
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 ;
91
105
}
92
106
93
107
@ ApiOperation (value = "HTTP 全链路灰度入口" , tags = {"入口应用" })
@@ -104,7 +118,7 @@ public String aZone(HttpServletRequest request) {
104
118
}
105
119
}
106
120
return "A" + serviceTag + "[" + currentZone + "]" + " -> " +
107
- restTemplate .getForObject ("http://sc-B/b-zone" , String .class );
121
+ loadBalancedRestTemplate .getForObject ("http://sc-B/b-zone" , String .class );
108
122
}
109
123
110
124
@ ApiOperation (value = "Dubbo 全链路灰度入口" , tags = {"入口应用" })
0 commit comments