使用Quarkus/Mutiny在Reactive REST GET端点中分发阻止服务 [英] Dispatch a blocking service in a Reactive REST GET endpoint with Quarkus/Mutiny

查看:93
本文介绍了使用Quarkus/Mutiny在Reactive REST GET端点中分发阻止服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我已经使用回调结构在Quarkus/Mutiny中实现了Reactive REST GET端点;

ServiceResource只是将呼叫转发到服务.

MyRequestService创建一个MyJsonResultSupplier并将其通过方法item()传递给Mutiny Uni.生成的Uni将返回到ServiceResource.

Mutiny对供应商使用MyJsonResult的get()方法.调用使用信号量mMyJsonResultSupplierSemaphore上的获取阻塞.接下来,另一个工作线程调用方法ready(),该方法设置mMyJsonResult并向Mutiny释放信号量mMyJsonResultSupplierSemaphore解除阻塞方法get().

Mutiny完全隐藏了故事的反应部分,因此您只需在注册的供应商内阻止方法调用即可.

Lately i've implemented a Reactive REST GET endpoint with Quarkus/Mutiny using a callback structure;

Connect MyRequestService to Reactive REST GET endpoint with Quarkus/Mutiny

After finishing, I was wondering how this is settled with a call to a blocking service;

How do i call a blocking service from my Reactive REST GET endpoint with Quarkus/Mutiny

解决方案

I didn't see a quick answer in the documentation, but it turned out to be quite simple;

The ServiceResource just forwards the call to the Service.

MyRequestService creates a MyJsonResultSupplier and delivers this to the Mutiny Uni with method item(). The resulting Uni is returned to the ServiceResource.

Mutiny uses method get() on the Supplier for a MyJsonResult. The call blocks with an acquire on semaphore mMyJsonResultSupplierSemaphore. Next, another worker thread calls method ready() which sets mMyJsonResult and releases semaphore mMyJsonResultSupplierSemaphore unblocking method get() towards Mutiny.

Mutiny completely hides the reactive part of the story, so you can just block on a method call within a registered supplier.

这篇关于使用Quarkus/Mutiny在Reactive REST GET端点中分发阻止服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆