【发布时间】:2021-09-12 15:22:02
【问题描述】:
假设我有一个描述另一个休息服务的接口。它看起来像这样:
@Produces("application/json")
public interface PetApi {
@GET
@Path("pet/{petId}")
String getPet(@PathParam("petId") Long petId);
}
当我调用它时它工作正常:
private static void testPet() {
PetApi petApi = JAXRSClientFactory.create("https://petstore.swagger.io/v2", PetApi.class);
String petDescr = petApi.getPet(1L);
System.out.println(petDescr);
}
现在我想改进此代码以用于响应式流程。 apache CXF 可以为响应式代码生成代理吗?以这种方式调用代码将如下所示:
private static void testPet() {
PetApi petApi = JAXRSClientFactory.create("https://petstore.swagger.io/v2", PetApi.class);
CompletionStage<String> petDescrCs = petApi.getPet(1L);
petDescrCs.thenAccept(System.out::println);
}
外部休息服务的接口是:
@Produces("application/json")
public interface PetApi {
@GET
@Path("pet/{petId}")
CompletionStage<String> getPet(@PathParam("petId") Long petId);
}
楼上的代码不起作用。这是我的看法。我的问题是有什么方法可以实现这样的功能
或者也许有人知道另一个可以构建这样的反应式休息代理的框架
【问题讨论】:
标签: java rest jax-rs cxf feign