BAEL-1174: A Quick Guide to Spring Cloud Consul: Fix Ribbon client
sasd a
This commit is contained in:
parent
bec94e9508
commit
1f7572884b
|
@ -8,7 +8,10 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
|||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
@ -30,12 +33,17 @@ public class DiscoveryClientApplication {
|
|||
return restTemplate().getForEntity(serviceUrl().resolve("/ping"), String.class)
|
||||
.getBody();
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/ping")
|
||||
public String ping() {
|
||||
return "pong";
|
||||
}
|
||||
|
||||
@RequestMapping("/my-health-check")
|
||||
public ResponseEntity<String> myCustomCheck() {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
public URI serviceUrl() {
|
||||
return discoveryClient.getInstances("myApp")
|
||||
.stream()
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -19,7 +21,7 @@ public class RibbonClientApplication {
|
|||
RestTemplate getRestTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
RestTemplate restTemplate;
|
||||
|
||||
|
@ -27,12 +29,17 @@ public class RibbonClientApplication {
|
|||
public String home() {
|
||||
return restTemplate.getForObject("http://myApp/ping", String.class);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/ping")
|
||||
public String ping() {
|
||||
return "pong";
|
||||
}
|
||||
|
||||
@RequestMapping("/my-health-check")
|
||||
public ResponseEntity<String> myCustomCheck() {
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(RibbonClientApplication.class).web(true)
|
||||
.run(args);
|
||||
|
|
Loading…
Reference in New Issue