反应性端点设计

Reactive end-points design

我正在学习 WebFlux。 Wiki 说响应式编程是:

For example, in an imperative programming setting, a:=b+c would mean that a is being assigned the result of b+c in the instant the expression is evaluated, and later, the values of b and/or c can be changed with no effect on the value of a.

However, in reactive programming, the value of a is automatically updated whenever the values of b and/or c change; without the program having to re-execute the sentence a:=b+c to determine the presently assigned value of a.

好的。当我复制 example like:

@RestController
public class PersonController {

    private final PersonRepository repository;

    public PersonController(PersonRepository repository) {
        this.repository = repository;
    }

    @PostMapping("/person")
    Mono<Void> create(@RequestBody Publisher<Person> personStream) {
        return this.repository.save(personStream).then();
    }

    @GetMapping("/person")
    Flux<Person> list() {
        return this.repository.findAll();
    }

    @GetMapping("/person/{id}")
    Mono<Person> findById(@PathVariable String id) {
        return this.repository.findOne(id);
    }
}

然后我回到第 2 页(没有刷新),我没有看到更新的人员列表,应该吗?

另外,这里应该如何进行UPDATE/DELETE操作?

我猜你指的是 the reactive programming wikipedia page 并且可能对那个例子读得太多了。 此示例(以及著名的电子表格示例)通常指向 UI 富应用程序,这些应用程序正在侦听用户事件并发布应用程序事件以更新 UI。

反应式编程和反应式流本身不足以建立这样的基础设施。

在您的 Controller 中,以反应方式执行操作并发布值:使用背压支持并访问反应式 API 来组合它们。呈现 JSON 响应后,客户端不会从服务器接收新元素。

不过,您可以通过发布事件并在服务器和浏览器之间建立持久连接(例如 SSE)来创建这样的系统。