我对通过 HTTP 从 Play Framework 应用程序使用 Spring WebFlux 应用程序有一些疑问,您能否提供一些帮助?
微服务A是一个响应式(Reactive)Spring WebFlux,用Java 8、SpringBoot 2.1.4编写,它公开了这个API:
@Autowired private ReactiveCustomerRepository customerRepository;
@GetMapping("/customers")
public Flux<Customer> getAllCustomers() {
Flux<Customer> c = customerRepository.findAll().delayElements(Duration.ofMillis(5000));
return c;
}
我想通过 HTTP 从 Play Framework 微服务 B 以 react 方式使用它。
您能否提供一些关于如何实现这一目标的建议或小片段?
感谢您的帮助。
最佳答案
您可以尝试使用支持流式传输的不同内容类型 - application/stream+json
。 Spring WebFlux 将序列化各个 Flux 元素并通过网络将它们一一发送。查看以下有关它的 SO 线程:Spring WebFlux Flux behavior with non streaming application/json
在 play-ws 端,您应该能够以 Source[T]
形式接收此数据。
关于Java:从 Play Framework 应用程序使用 Spring WebFlux 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56094802/