英文:
Is there a way to create Firebase real time database event listeners?
问题
我正在尝试将实时事件监听器集成到使用Firebase实时数据库的应用程序中。
我看到了这篇帖子(https://github.com/firebase/firebase-admin-go/issues/229),讨论了这个问题,但似乎官方SDK不会实现这个功能。
我还发现了Firebase的REST/Streaming端点(https://firebase.google.com/docs/reference/rest/database/#section-streaming),考虑使用它来集成实时监听器。
我的问题是,有没有推荐的方法来实现这个功能?(Websockets、回调、通道等)是否已经有一个库可以做到这一点,这样我就不必从头编写代码来实现这个功能了?
英文:
I am trying to integrate real time event listeners into my application that utilizes firebase realtime database.
I came across this post that discussed this but it seems that it will not be implemented in the official SDK.
I also came across the firebase REST/Streaming endpoints and was considering using this to integrate realtime listeners.
My question is, is there a recommended way to achieve this? (Websockets, callbacks, channels ect.) Is there already a library that does this so I don't have to write code from scratch to achieve this functionality?
答案1
得分: 0
Firebase的原生Web套接字协议没有文档记录。如果不使用原生SDK,你可以通过使用Hiranya在Github问题中提供的REST Streaming API来接近原生SDK的行为。我在各种项目和各种语言中都这样做过(尽管从未在Go中),这通常是一个合理的方法,尽管比原生Web套接字稍微低效,因为它需要单独的连接来读取和写入数据。
要开始使用,我建议查看以下内容:
- 宣布实时数据库的REST流API的博客文章
- Python和Ruby的示例客户端。
- Go的REST SSE实现。
英文:
Firebase's native web socket wire protocol is not documented. The closest you can get to the behavior of the native SDKs (outside of using those) with a public API is by using the REST Streaming API that Hiranya also linked in the Github issue. I've done this for various projects in various languages (though never in Go), and it's often a reasonable approach though slightly less efficient than the native web sockets, as it needs separate connections for reading and writing data.
To get started, I recommend checking out:
- The blog post announcing the REST streaming API for Realtime Database
- The sample clients for Python and Ruby.
- REST SSE implementations for Go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论