本文介紹了Resilience4j重試-記錄來自客戶端的重試嘗試?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
是否可以使用彈性4j記錄客戶端的重試嘗試?
可能通過某種配置或設置。
目前,我正在使用基于Spring Boot Webflow批注的Resilience4j。
它工作得很好,這個項目很棒。
我們將服務器日志放在服務器端,以查看由于重試而進行了相同的http調用(我們記錄時間、客戶端IP、請求ID等)我可以擁有客戶端日志嗎?
我期望看到類似";Resilience4j-客戶端:第一次嘗試失敗,原因是出現異常,正在重試,出席人數為2。第二次嘗試失敗,原因是出現異常,重試出席人數為3。第三次嘗試成功!&q;
差不多吧。有沒有一個屬性,一些配置,一些設置,可以幫助輕松做到這一點,請?而不添加太多鍋爐代碼。
@RestController
public class TestController {
private final WebClient webClient;
public TestController(WebClient.Builder webClientBuilder) {
this.webClient = webClientBuilder.baseUrl("http://localhost:8443/serviceBgreeting").build();
}
@GetMapping("/greeting")
public Mono<String> greeting() {
System.out.println("Greeting method is invoked ");
return someRestCall();
}
@Retry(name = "greetingRetry")
public Mono<String> someRestCall() {
return this.webClient.get().retrieve().bodyToMono(String.class);
}
}
謝謝
推薦答案
幸運的(或不幸的)有一個未記錄的功能:)
您可以添加RegistryEventConsumer Bean,以便將事件使用者添加到任何重試實例。
@Bean
public RegistryEventConsumer<Retry> myRetryRegistryEventConsumer() {
return new RegistryEventConsumer<Retry>() {
@Override
public void onEntryAddedEvent(EntryAddedEvent<Retry> entryAddedEvent) {
entryAddedEvent.getAddedEntry().getEventPublisher()
.onEvent(event -> LOG.info(event.toString()));
}
@Override
public void onEntryRemovedEvent(EntryRemovedEvent<Retry> entryRemoveEvent) {
}
@Override
public void onEntryReplacedEvent(EntryReplacedEvent<Retry> entryReplacedEvent) {
}
};
}
日志條目如下:
2020-10-26T13:00:19.807034700+01:00[Europe/Berlin]: Retry 'backendA', waiting PT0.1S until attempt '1'. Last attempt failed with exception 'org.springframework.web.client.HttpServerErrorException: 500 This is a remote exception'.
2020-10-26T13:00:19.912028800+01:00[Europe/Berlin]: Retry 'backendA', waiting PT0.1S until attempt '2'. Last attempt failed with exception 'org.springframework.web.client.HttpServerErrorException: 500 This is a remote exception'.
2020-10-26T13:00:20.023250+01:00[Europe/Berlin]: Retry 'backendA' recorded a failed retry attempt. Number of retry attempts: '3'. Giving up. Last exception was: 'org.springframework.web.client.HttpServerErrorException: 500 This is a remote exception'.
這篇關于Resilience4j重試-記錄來自客戶端的重試嘗試?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,