feat: add delay interface in tsf-example. (#1705)

Co-authored-by: Fishtail <49390359+fuyuwei01@users.noreply.github.com>
pull/1706/head
Haotian Zhang 3 weeks ago committed by GitHub
parent 7007af5d90
commit 021959402c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -13,3 +13,4 @@
- [feat: support shortest response time lb and least connection lb](https://github.com/Tencent/spring-cloud-tencent/pull/1702)
- [feat:support traffic mirroring.](https://github.com/Tencent/spring-cloud-tencent/pull/1703)
- [feat: support custom quickstart circuitbreak delay time.](https://github.com/Tencent/spring-cloud-tencent/pull/1704)
- [feat: add delay interface in tsf-example.](https://github.com/Tencent/spring-cloud-tencent/pull/1705)

@ -160,7 +160,7 @@
"description": "polaris loadbalancer."
},
{
"name": "spring.cloud.loadbalancer.strategy",
"name": "spring.cloud.loadbalancer.strategies",
"type": "java.lang.String",
"defaultValue": "polarisWeightedRoundRobin",
"description": "loadbalancer strategy."

@ -91,6 +91,15 @@ public class ConsumerController {
}
@RequestMapping(value = "/echo-rest/slow/{str}", method = RequestMethod.GET)
public String restSlowProvider(@PathVariable String str) {
try {
return restTemplate.getForObject("http://provider-demo/echo/slow/" + str, String.class);
}
catch (CallAbortedException callAbortedException) {
return callAbortedException.getMessage();
}
}
@RequestMapping(value = "/echo-rest-async/{str}", method = RequestMethod.GET)
public String restAsync(@PathVariable String str,
@RequestParam(required = false) String tagName,

@ -60,6 +60,8 @@ public class ProviderController {
private boolean ifBadGateway = false;
private int delay = 1000;
// 获取本机ip
public static String getInet4Address() {
Enumeration<NetworkInterface> nis;
@ -91,6 +93,14 @@ public class ProviderController {
return echoHello;
}
@RequestMapping(value = "/setDelay", method = RequestMethod.GET)
public String setSleepTime(@RequestParam("delay") int delay) {
this.delay = delay;
String result = "set delay time success, delay: " + delay;
LOG.info(result);
return result;
}
@RequestMapping(value = "/echo/{param}", method = RequestMethod.GET)
public ResponseEntity<String> echo(@PathVariable String param) {
if (ifBadGateway) {
@ -143,7 +153,7 @@ public class ProviderController {
*/
@RequestMapping(value = "/echo/slow/{param}", method = RequestMethod.GET)
public String echoSlow(@PathVariable String param, @RequestParam(required = false) Integer delay) throws InterruptedException {
int sleepTime = delay == null ? 1000 : delay;
int sleepTime = delay == null ? this.delay : delay;
LOG.info("slow request param: [" + param + "], Start sleep: [" + sleepTime + "]ms");
Thread.sleep(sleepTime);
LOG.info("slow request param: [" + param + "], End sleep: [" + sleepTime + "]ms");

Loading…
Cancel
Save