Mus*_*taq 3 rest quarkus smallrye-reactive-messaging
我正在尝试学习在 Quarkus 框架上使用 ReactiveMongoClient。
我以 Uni> 的身份发送回复部分成功
@GET
@Path("/unpaginated")
public Uni<List<Staff>> unpaginatedStaffList() {
return staffService.getStaffResponse();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试获取其他类(StaffResponse)的对象以包含用于分页的 Link 对象时,我没有获得任何 Staff 记录。(现在我已经硬编码了分页链接)
@GET
@Path("/paginated")
public StaffResponse paginatedStaffList() {
List<Link> links = LinkService.getLinks("/staff?page=2&limit=20", "next");
Uni<List<Staff>> staff = (Uni<List<Staff>>) staffService.getStaffResponse();
return new StaffResponse(links, staff);
}
Run Code Online (Sandbox Code Playgroud)
响应中的“工作人员”为空。
MongoClient 正在返回员工列表,看起来 Response 对象没有获取列表。尝试阅读 SmallRye Mutiny 文档 - 无法解决。
请帮忙。
我已将代码提交到:https://github.com/doepradhan/staffApi 和示例 json 数据文件(https://github.com/doepradhan/staffApi/blob/master/sample-staff-data.json)
非常感谢您的热心帮助。
小智 5
你不能混用两种方法。你需要使用Uni端点的输出。这意味着您需要将两个输入源转换为 Uni,将它们组合起来,然后映射到StaffResponse.
LinkService为返回Uni(或使用Uni.createFrom().item(links))public StaffResponse(List<Link> links, List<Staff> staff) {
this.links = links;
this.staff = staff;
}
Run Code Online (Sandbox Code Playgroud)
Uni<Tuple>,然后将其映射到StaffResponse: @GET
@Path("/paginated")
public Uni<StaffResponse> paginatedStaffList() {
final Uni<List<Link>> links =
Uni.createFrom().item(LinkService.getLinks("/staff?page=2&limit=20", "next"));
Uni<List<Staff>> staff = staffService.getStaffResponse();
return staff.and(links).map(it -> new StaffResponse(it.getItem2(), it.getItem1()));
}
Run Code Online (Sandbox Code Playgroud)
我在这里创建了一个有效的 PR
| 归档时间: |
|
| 查看次数: |
7259 次 |
| 最近记录: |