java - 在 Quarkus 中调用具有自定义媒体类型的另一个服务的请求
问题描述
我正在开发公司内部的 Quarkus 服务。在这个服务中,我需要使用自定义的媒体类型异步调用另一个内部服务。
当我关注这个官方文档并写下这样的内容时:
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
@Path("/api")
@RegisterRestClient
public interface InternalService {
String CUSTOM_TYPE = "application/custom";
@GET
@Path("/hello/{id}")
@Produces({CUSTOM_TYPE})
Uni<EntityClass> getHello(@PathParam("id") long id);
}
在我的情况下,这EntityClass
实际上是 protobuf 消息。
在示例中(https://quarkus.io/guides/rest-client),看起来可以直接注入 bean:
@Inject
@RestClient
CountriesService countriesService;
我有几个问题:
- 是否
resteasy
已经提供了常见媒体类型的实现? - 如何
InternalService
为我的自定义媒体类型实现接口?
解决方案
- 是的。请在此处查看:
- https://docs.jboss.org/resteasy/docs/4.6.0.Final/userguide/html_single/index.html#Content_Marshalling_Providers。Quarkus 增加了一些额外的支持。
- 只需创建您自己的 Provider 来处理自定义媒体类型并注册它: