Firebase事件保证:事件顺序 [英] Firebase Event Guarantee: Event Order

查看:46
本文介绍了Firebase事件保证:事件顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Firebase,并且对以下网址中列出的Firebase事件保证有疑问: 事件保证.

I am just getting started with Firebase and had a question regarding the Firebase Event Guarantees listed at the following URL: Event Guarantees.

其中一项保证规定,始终将单个客户端的写入操作写入服务器,并按顺序广播给其他用户.

One of the guarantees states that writes from a single client will always be written to the server and broadcast out to other users in-order.

此保证是否还暗示客户端将按照广播的顺序接收单个客户端广播的事件,或者是否有可能以广播顺序接收事件?

Does this guarantee also imply that clients will receive events broadcast by a single client in the order that they were broadcast, or is it possible to receive events out of the order they were broadcast?

例如,如果一个客户端添加了一个节点,然后向该节点添加了一个子节点,我是否保证其他客户端将以相同的顺序看到这些事件?

For example, if one client adds a node, then adds a child to that node, am I guaranteed that other clients will see those events in the same order?

推荐答案

唯一的保证是这些值最终将保持一致.仔细考虑,这是唯一合理的答案.互联网上的任何操作都可能被过程中的任何活动部分无限期地延迟,从而导致客户端接收到乱序事件,无论它们到达服务器的顺序如何.

The only guarantee is that the values will be eventually consistent. Thinking this through, it's the only reasonable answer. Any operation over the internet could be delayed indefinitely by any moving part in the process, thus producing out-of-order events received by the client, regardless of the order they reach the server.

因此,可以保证所有客户端最终都将看到两个添加的子节点,并且它们在所有客户端之间(最终)将保持一致.

Thus, you are guaranteed that all the clients will see both of the added child nodes eventually, and that they will be consistent across all the clients (eventually).

如果要保证事件的顺序,请使用消息队列-这是对Firebase使用方式的一种改编,但不是唯一的.使用 push()方法很容易实现,它将创建按时间顺序排列的唯一ID.

If you want to guarantee the order of events, you are using a messaging queue--which is one adaptation of how you can use Firebase, but not the only one. This is easily achieved using the push() method, which creates chronologically ordered, unique ids.

您还可以添加时间戳并利用 orderByChild 方法对记录进行排序.

You can also throw in a timestamp and utilize the orderByChild method to sort records.

这篇关于Firebase事件保证:事件顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆