Quarkus/Microprofile REST Client 不会重试失败的调用

问题描述

更新:在 https://github.com/quarkusio/quarkus/issues/17145

下创建的问题

使用 Quarkus 1.13.3.Final 我试图在使用 Microprofile REST Client 的 Quarkus 风格并根据 documentation:

当返回一个 Uni 时,每个订阅都会调用远程服务。这意味着您可以通过在 Uni 上重新订阅来重新发送请求,或者使用重试[...]

但是当我通过返回 Uni.createFrom().failure(new RuntimeException()); 使请求在另一端失败时,客户端只是挂起,直到发生预设延迟的设置尝试次数,但没有迹象表明这些尝试会到达其他服务.远程端点的代码只运行一次。

我对新的 Quarkus Reactive REST Client 和旧的都进行了相同的尝试,每次都使用 Mutiny Uni 作为返回值,设置和不设置最大重试次数、等待时间等。由 Uni 的 .onFailure().retry() API 提供。

REST 客户端:

@Path("/dataservice")
@RegisterRestClient(configKey = "restclient")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface RestClientToDataService {

    @POST
    Uni<DataObject> getDataObject(String data);

}

REST 客户端属性

restclient/mp-rest/url=http://localhost:${remote.service.port}

REST 客户端被注入并在调用方使用:

@Path("")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ReactiveController {

    private final RestClientToDataService dataServiceClient;

    public ReactiveController(@RestClient RestClientToDataService dataServiceClient) {
        this.dataServiceClient = dataServiceClient;
    }


    @GET
    @Path("/test")
    public void test() {

        dataServiceClient.getDataObject("data")
                .onFailure().retry()
                .withBackOff(Duration.ofMillis(100),Duration.ofMillis(200))
                .atMost(6);
    }
}

远程服务端:

@Path("/dataservice")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DataServiceController {

    @POST
    public Uni<DataObject> getDataObject(String data) {
        System.out.println(">>>>>>>>>>>>>>>> DATA CALL");
        return Uni.createFrom().failure(new RuntimeException("Failed DataServiceController for " + data));
    }
}

调用方服务不产生任何日志,但从远程服务日志中可以明显看出,尽管将重试计数设置为 6,但端点仅被调用一次,或者可能有某种缓存适合我的任何一方在文档中找不到任何内容

>>>>>>>>>>>>>>>> DATA CALL
2021-05-11 14:36:11,912 ERROR [org.jbo.res.rea.ser.cor.ExceptionMapping] (vert.x-eventloop-thread-21) Request Failed : java.lang.RuntimeException: Failed DataServiceController for data
    at com.neticle.reactive.service.dataservice.DataServiceController.getDataObjects(DataServiceController.java:43)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects$$superaccessor1(DataServiceController_Subclass.zig:211)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass$$function$$5.apply(DataServiceController_Subclass$$function$$5.zig:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects(DataServiceController_Subclass.zig:166)
    at com.neticle.reactive.service.dataservice.DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.invoke(DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.zig:45)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:834)

2021-05-11 14:36:11,913 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (vert.x-eventloop-thread-21) HTTP Request to /dataservice?batch=1620736571899 Failed,error id: 2c35e7ff-aeb6-48c1-b76f-0598a1b18294-34: java.lang.RuntimeException: Failed DataServiceController for data
    at com.neticle.reactive.service.dataservice.DataServiceController.getDataObjects(DataServiceController.java:43)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects$$superaccessor1(DataServiceController_Subclass.zig:211)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass$$function$$5.apply(DataServiceController_Subclass$$function$$5.zig:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects(DataServiceController_Subclass.zig:166)
    at com.neticle.reactive.service.dataservice.DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.invoke(DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.zig:45)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:834)

2021-05-11 14:36:11,913 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (vert.x-eventloop-thread-21) Request Failed: java.lang.RuntimeException: Failed DataServiceController for data
    at com.neticle.reactive.service.dataservice.DataServiceController.getDataObjects(DataServiceController.java:43)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects$$superaccessor1(DataServiceController_Subclass.zig:211)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass$$function$$5.apply(DataServiceController_Subclass$$function$$5.zig:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at com.neticle.reactive.service.dataservice.DataServiceController_Subclass.getDataObjects(DataServiceController_Subclass.zig:166)
    at com.neticle.reactive.service.dataservice.DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.invoke(DataServiceController$quarkusrestinvoker$getDataObjects_2fa034de4b478d9f7f54657d56e0c77c0a510d65.zig:45)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:834)


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)