BAEL-1174: A Quick Guide to Spring Cloud Consul: Fix Ribbon client

sasd

a
This commit is contained in:
Jose Carvajal 2017-12-01 16:56:34 +01:00
parent bec94e9508
commit 1f7572884b
2 changed files with 18 additions and 3 deletions

View File

@ -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()

View File

@ -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);