Skip to content

Commit

Permalink
feat:optimize quickstart circuit-breaker examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyeBeFreeman committed Oct 19, 2023
1 parent 9b295cf commit e99afb0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ public String circuitBreak() {
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port);
}

@GetMapping("/faultDetect")
public String health() {
LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port);
return String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,34 +107,56 @@ public String echoHeader(@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METAD
@GetMapping("/circuitBreak")
public ResponseEntity<String> circuitBreak() throws InterruptedException {
if (ifBadGateway) {
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY);
}
if (ifDelay) {
Thread.sleep(100);
Thread.sleep(200);
LOG.info("Quickstart Callee Service [{}:{}] is called slow.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK);
}
LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called wrong.", ip, port), HttpStatus.OK);
LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port), HttpStatus.OK);
}

@GetMapping("/setBadGateway")
public void setBadGateway(@RequestParam boolean param) {
public String setBadGateway(@RequestParam boolean param) {
this.ifBadGateway = param;
if (param) {
LOG.info("info is set to return HttpStatus.BAD_GATEWAY.");
return "info is set to return HttpStatus.BAD_GATEWAY.";
}
else {
LOG.info("info is set to return HttpStatus.OK.");
return "info is set to return HttpStatus.OK.";
}
this.ifBadGateway = param;
}

@GetMapping("/setDelay")
public void setDelay(@RequestParam boolean param) {
public String setDelay(@RequestParam boolean param) {
this.ifDelay = param;
if (param) {
LOG.info("info is set to delay 100ms.");
LOG.info("info is set to delay 200ms.");
return "info is set to delay 200ms.";
}
else {
LOG.info("info is set to no delay.");
return "info is set to no delay.";
}
this.ifDelay = param;
}

@GetMapping("/faultDetect")
public ResponseEntity<String> health() throws InterruptedException {
if (ifBadGateway) {
LOG.info("Quickstart Callee Service [{}:{}] is detected wrong.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected wrong.", ip, port), HttpStatus.BAD_GATEWAY);
}
if (ifDelay) {
Thread.sleep(200);
LOG.info("Quickstart Callee Service [{}:{}] is detected slow.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected slow.", ip, port), HttpStatus.OK);
}
LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port);
return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port), HttpStatus.OK);
}
}

0 comments on commit e99afb0

Please sign in to comment.