简体   繁体   English

Spring Reactive Programming - “监听”数据存储区的更改

[英]Spring Reactive Programming - “Listen” to changes on datastore

When using Spring's new Reactive technology, is it possible to "listen" on a datastore for any changes, so you get a callback for any changes on it? 使用Spring的新Reactive技术时,是否可以在数据存储上“监听”任何更改,以便对其进行任何更改进行回调? Imagine being able to suscribe on a MongoDB repository, so a change in the database will trigger a given method? 想象一下能够在MongoDB存储库上进行控制,那么数据库中的更改是否会触发给定的方法?

Continuous queries depend on the used data store. 连续查询取决于使用的数据存储。 I'm currently aware of three stores that are capable of such a feature: 我目前知道有三个能够提供这种功能的商店:

  • MongoDB (Capped collections and tailable cursors, supported via @Tailable in Spring Data Repositories) MongoDB(封顶集合和tailable游标,通过Spring Data Repositories中的@Tailable支持)
  • Redis (Using either Pub/Sub messaging or listening to keyspace notifications, not yet supported in a reactive way with Spring Data Redis, but you can build it yourself or submit a PR) Redis(使用Pub / Sub消息或监听密钥空间通知,但尚未以Spring Data Redis的方式支持,但您可以自己构建或提交PR)
  • Apache Geode (previously GemFire) that supports continuous queries (not yet supported in a reactive way with Spring Data for Apache Geode). 支持连续查询的Apache Geode(以前称为GemFire)(尚未以Spring Data for Apache Geode的反应方式支持)。

A reactive type is not required to emit a finite number of items per se. 反应型本身不需要发射有限数量的物品。 An infinite stream can be anything you want to listen to/process for a longer time. 无限流可以是您想要收听/处理更长时间的任何内容。 A messaging system (JMS) is a good example for a message listener for a traditional approach. 消息传递系统(JMS)是传统方法的消息监听器的一个很好的示例。 You use a messaging system in the way to emit messages through the stream. 您使用消息传递系统通过流发送消息。 This works in similar for the previously mentioned data stores. 这适用于前面提到的数据存储。

For example, MongoDB can use tailable cursors on a capped collection and emit data on the stream. 例如,MongoDB可以在上限集合上使用tailable游标并在流上发出数据。 As soon as a client inserts a new document into the collection, the server emits the document to the client which pushes it through the stream. 一旦客户端将新文档插入到集合中,服务器就会将文档发送到客户端,从而将其推送到流中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Framework WebFlux 响应式编程 - Spring Framework WebFlux Reactive Programming Spring 反应式编程和关系数据库:使用关系 - Spring reactive programming and relational databases: using relationships Spring 5 Web Reactive Programming - 从Spring Reactive Controller解组流式数据的JSON时的WebClient ClassCastException - Spring 5 Web Reactive Programming - WebClient ClassCastException when unmarshalling JSON from Spring Reactive Controller that streams data 执行时间响应式编程 - Execution time reactive programming 如何转换单声道<List<something> &gt; 列出<something>进入反应式编程Spring Boot? - How can I convert Mono<List<something>> to List<something> into reactive programming spring boot? 如何在不以特定时间间隔轮询批处理作业执行表的情况下监听Spring批处理作业状态的更改? - How to listen to changes in spring batch job status without polling batch job execution table at a certain time interval? 响应式Spring Mono和doOnNext - Reactive Spring Mono and doOnNext 反应式弹簧授权服务器 - Reactive spring authorization server Spring 反应性与 Oracle ClassCastException - Spring Reactive with Oracle ClassCastException Spring 5反应式异常处理 - Spring 5 reactive exception handling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM