-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathAController.java
58 lines (44 loc) · 1.83 KB
/
AController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.alibabacloud.mse.demo;
import com.alibabacloud.mse.demo.bean.Consumer;
import com.alibabacloud.mse.demo.service.HelloServiceB;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import static com.alibabacloud.mse.demo.ConsumerApplication.SERVICE_TAG;
@RestController
public class AController {
private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newSingleThreadScheduledExecutor();
@Reference(application = "${dubbo.application.id}", version = "1.0.0")
private HelloServiceB helloServiceB;
@Autowired
private Consumer consumer;
@Autowired
RestTemplate restTemplate;
@GetMapping("/a")
public String a(HttpServletRequest request) {
return "A"+SERVICE_TAG+"[" + request.getLocalAddr() + "]" + " -> " +
restTemplate.getForObject("http://provider/b", String.class);
}
@GetMapping("/dubbo")
public String dubbo(HttpServletRequest request) {
return "A"+SERVICE_TAG+"[" + request.getLocalAddr() + "]" + " -> " +
helloServiceB.hello("A");
}
@PostConstruct
private void printConfig() {
EXECUTOR_SERVICE.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
System.out.println(consumer.getName());
}
},0,2, TimeUnit.SECONDS);
}
}