首页 > 解决方案 > 为什么不推荐使用 StreamListener

问题描述

我正在Spring Cloud Stream 3.1.2使用KafkaStreams. 编程模型有:

后者使用注解作为提供 Spring 以供使用的所有其他注解。但是,有人提到

从 3.1.0 版本的 binder 开始,我们建议对基于 Kafka Streams binder 的应用程序使用上述函数式编程模型。从 Spring Cloud Stream 的 3.1.0 开始,不推荐使用对 StreamListener 的支持。

因为我认为旧模型更具可读性(至少对我而言)。谁能解释为什么决定弃用它以支持函数式编程并将其删除?

标签: springspring-cloud-streamspring-cloud-stream-binder-kafka

解决方案


来自 Spring 博客文章 ( https://spring.io/blog/2019/10/17/spring-cloud-stream-functional-and-reactive ) 它说a functional programming model in Spring Cloud Stream (SCSt). It’s less code, less configuration. Most importantly, though, your code is completely decoupled and independent from the internals of SCSt这有利于使用 Project Reactor ( https://projectreactor.io/ )提供的事件流抽象(例如 Flux 和 Mono )。命令式函数会在每个单独的事件上触发,而响应式函数会触发一次。


推荐阅读