0

更新:在https://github.com/quarkusio/quarkus/issues/17145下创建的问题

使用 Quarkus 1.13.3.Final 我试图在使用 Microprofile REST 客户端的 Quarkus 风格并根据文档找出故障处理:

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

但是,当我通过返回 a 使请求在另一端失败时,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)


4

0 回答 0