【发布时间】:2021-06-17 03:05:32
【问题描述】:
我想添加代码来模拟我的 WebClient 调用中的延迟,以便我可以确保我的超时/重试/等正常工作。
由于 WebClient 是响应式的并且使用线程池,因此 Thread.sleep 似乎会以 WebClient 在实际使用中通常不会被阻塞的方式阻塞线程。
有没有更好的方法来模拟这种延迟?
public class LatencyInducingRequestInterceptor implements ClientHttpRequestInterceptor {
public ClientHttpResponse intercept(
HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// do nothing
}
return response;
}
}
【问题讨论】:
标签: spring-boot spring-webclient spring-boot-chaos-monkey