Firebase是否有针对写入操作的超时政策? [英] Does Firebase have a timeout policy for write operations?

查看:210
本文介绍了Firebase是否有针对写入操作的超时政策?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

setValue()将数据保存到Firebase。如果连接非常慢,会发生什么情况。保存数据是否有超时限制?如果超时,它会重试吗?如果它重试,多少次?

另外,是否有超时读取方法 onDataChange(DataSnapshot快照)和更新方法?

有没有办法设置你自己的超时限制?

解决方案新的Firebase(...))时,它建立一个到服务器的WebSocket连接。所有数据都通过预先建立的连接进行传输。

当您调用 setValue()当客户端添加一个侦听器(带有 addValueEventListener()或类似的)时,服务器将通过打开的套接字发送更新到你的客户端,因为没有建立连接,所以暂停不会真正起作用。

当客户端和服务器之间的连接丢失时,客户会尝试r电子建立连接。它在这里使用了一个指数回退,所以最初它经常尝试重新连接,并逐渐减少频率。

虽然没有连接到服务器,客户端将继续服务所有已经从内存中收到的数据(或者如果你已经启用了磁盘持久化,则在磁盘上)缓存。来自客户端的任何写入操作将排队等待发送到服务器。即使客户端没有连接到服务器,本地事件(例如触发例如你的 onDataChange()方法)也会立即触发。



这涵盖了很多的理由。如果您想了解更多关于这是如何工作的,最好的办法是在Android客户端启用调试日志记录( Firebase.getDefaultConfig()。setLogLevel(Level.DEBUG)))并检查当您放弃网络连接时出现在日志输出中的内容。这是非常有教育意义的,将回答比我在这里可以遇到的更多的问题。


There is setValue( ) to save data to Firebase. What happens if the connection is very very slow. Is there a timeout limit for saving data? If it does timeout, does it retry? If it retries, how many times?

Also, Is there timeout for reading method onDataChange(DataSnapshot snapshot) and updating methods?

Is there a way to set your own timeout limits?

解决方案

When a client first connects to Firebase (so when it executes the first new Firebase(...), it establishes a WebSocket connection to the server. After that all data is transferred over that pre-established connection.

When you call setValue() or another write operation, the command is sent over the open socket to the server. When a client adds a listener (with addValueEventListener() or similar), the server will send updates over the open socket to your client. Since there is no connection being established, time-outs don't really come into play here.

When the connection between client and server is somehow lost, the client will try to re-establish the connection. It uses an exponential back-off here, so initially it frequently tries to reconnect and progressively less frequently.

While there is no connection to the server, the client will keep serving all data it already received from its in memory (or on-disk if you've enabled disk persistence) cache. Any write operations from the client will be queued for sending to the server. Local events (that trigger e.g. your onDataChange() method) will trigger right away, even while the client is not connected to the server.

This covers a lot of ground. If you want to learn more about how this works, your best bet is to enable debug logging (Firebase.getDefaultConfig().setLogLevel(Level.DEBUG) in the Android client) and inspect what appears in the logging output when you drop your network connection. It's highly educational and will answer more questions than I ever can here.

这篇关于Firebase是否有针对写入操作的超时政策?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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