【发布时间】:2021-03-27 00:41:45
【问题描述】:
请提出关于 Java SpringBoot Webflux 与 Resilience4J(不是 Spring Cloud 断路器)的小问题。
我有以下直截了当:
@TimeLimiter(name = "methodOne", fallbackMethod = "fallbackMethod")
public Mono<String> methodOne(@RequestParam(value = "name", defaultValue = "World") String name) {
return WebClient.builder().baseUrl("http://localhost:8081/serviceBgreeting?name=" + name).build().get().retrieve().bodyToMono(String.class);
}
@TimeLimiter(name = "methodTwo", fallbackMethod = "fallbackMethod")
public Mono<String> methodTwo(@RequestParam(value = "name", defaultValue = "World") String name) {
return WebClient.builder().baseUrl("http://localhost:8082/anotherMethodTwo?name=" + name).build().get().retrieve().bodyToMono(String.class);
}
还有一个相同的被调用者fallbackMethod,由所有调用者共享,如:
public Mono<Object> fallBackMethod(Exception exception) {
System.out.println("For debug purpose, I need to know what is the exact method falling back to this fallback method");
return //the fallback thing needed;
请问,检索 methodOne 或 methodTwo 两种方法中的哪一种实际上是此后备的触发器的最佳方法是什么?
我有大约 1000 多个使用这种模式的方法,所以我不能只创建 1000 多个备用方法。 (比如 methodOne 掉到 fallbackOne,methodTwo 掉到 fallbackTwo 等等……,我不能)
我确信有一种聪明的方法可以让方法名称触发回退。
试过 StackWalker,它只提供(fallBackMethod、invoke、fallback、lambda$reactorOnErrorResume$1、onError 等),但不提供触发 fallBack 的方法。
请帮忙。
谢谢
【问题讨论】:
-
你想知道fallbackMethod是从
methodOne还是methodTwo调用的? -
正确,是的,请:)
-
你能检查这个链接吗stackoverflow.com/questions/421280/…
-
试过了,它没有给调用者(在我的情况下是methodOne,methodTwo),而是所有中间调用者(onError等:'()
标签: java resilience4j