[英]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: 我目前知道有三个能够提供这种功能的商店:
@Tailable
in Spring Data Repositories) MongoDB(封顶集合和tailable游标,通过Spring Data Repositories中的@Tailable
支持) 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.