我目前正在使用Firebase云功能,通过功能执行HTTP请求。 HTTP请求由3G模块完成,我需要始终读取数据库中的值更改。
该系统将用于一个应用程序,一旦DB发生变化,我应该通知3G模块,所以目前我正在使用HTTP请求。
$ git push --force origin deployment-scripts
Counting objects: 3, done.
Writing objects: 100% (3/3), 250 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://my.username@bitbucket.site.com/scm/dev.repo.git
+ 524095e...87e6bd7 deployment-scripts -> deployment-scripts (forced update)
这工作得非常好,问题是我在数据库发生更改之前保持HTTP请求处于打开状态,因此大约需要60分钟消耗Firebase提供的配额。
exports.moduleRequest = functions.https.onRequest((req, res) => {
var change = admin.database().ref('/userInfo');
////Once there is a change in any userInfo child, do something
change.once('child_changed', (snapshot) =>{
res.send(snapshot.val());
});
});
您知道是否有其他方法可以让这个系统正常工作?
答案 0 :(得分:0)
我发现解决我的问题的最简单和最好的方法是使用REST API,因为它允许我通过HTTP GET请求进行流式传输。它使用我的SIMCOM SIM5320 3G模块作为客户端,然后服务器在请求的路径上发送带有数据库更新的事件。