Long connection service is widely used in information reminder, instant messaging, push, live barrage, games and other scenarios. This article will introduce the long -connection service of the cloud development database -real -time data push, and use it to build a more vivid applet.
What is real -time data push
Through the real -time data push capacity of the cloud development database, the applet can listen to the database change in real time, that is, it supports the monitoring of the query statement given by the developer. Receive push containing updates and respond to real -time data changes.
Specific examples below: Client 1 modify data and meet the monitoring conditions. When the database is changed, the change content of the client 1 will be pushed to other clients.
What capabilities are available to help developers build applets
self -built -in -long connection service requires a complicated system architecture, and there are a lot of development work, making the development cost higher. After the development of the long connection service is put into use, it will inevitably bring additional maintenance. The maintenance of infrastructure and service safety also requires a lot of time and labor costs. At this time, developers can perform actual development of the applet. Access to the WeChat authority system to obtain user login and use WeChat open interfaces, etc., to achieve specific business logic based on long connection services. Students who do not understand cloud development can viewproduct documentation。
Using real -time data push has the following advantages:
- zero development
Using real -time data push does not need to write a complete service by writing the server code, reducing the development cost and the use threshold of the developer, and you can focus on the design and development of the core business.
Using real -time data push does not require access to the WeChat authentication system, naturally integrates native WeChat capabilities, seamlessly integrates with WeChat login, uses the box to use it, exempt authority to obtain WeChat user information, and use WeChat open interfaces. Reduce developers’ development and maintenance of authority functions.
- zero maintenance
Use real -time data push does not need to maintain infrastructure and safety management issues to reduce maintenance costs.
Everyone has heard of the online paragraph saying that there are no years, but some people go forward for you. We just learned about the natural advantages of zero development, zero maintenance, exemption from real -time data push. So who is behind these capable years of being quiet? Let’s unveil the mysterious veil of the real -time data push technology architecture.
Request from the small program to the access layer passes through the WebSocket protocol, and then to the security verification layer for permission verification. Safety verification provides simple ACL marks, and also supports high -leveldatabase security rulesgrammar implementation of refined access permissions control can be selected according to the actual business situation. For routing layers and monitoring push layers, it will be introduced in terms of availability, reliability and performance.
The service is available for service. The first is that the abnormal node is automatically eliminated to ensure that the service is normal when there is a problem with some nodes. Real -time data push routing layers block the abnormal nodes through the melting and automatic elimination mechanism of TARS. The monitoring push layer uses ETCD real -time heartbeat detection. The heartbeat is reported in 2 seconds, and the abnormalities are detected in 6 seconds. Immediately executed the relevant processing logic to achieve automatic elimination of the abnormal node. Secondly, improve performance and ensure availability through consistency hash solutions. Every time the long -roller inquiry request is queryid, the corresponding relationship between the request from the routing layer to the monitoring push layer is generated by the consistency hash, making the load balancing of the monitoring push layer. Finally, the same conditions correspond to the same queryid to improve performance.
From small programs to real -time data push services are long -term inquiry and have no state, providing escorts for reliable business. Event self -increased IDs can ensure that receiving push events is orderly. In addition, the two -level caching of the local and Redis caches to ensure data security. Support the client to drop the line for 3 minutes, the incident does not lose, and the incident can be received normally after the break is re -connected.
Real -time data push service performance, we have done some optimization work:
- Use the data structure of the tree to save the Watch condition as the index, and optimize the monitoring condition matching index.
- For the matching of changes, the multi -corrector concurrent flow water line is used: matching events, push events, cache events.
- When there are multiple incidents that meet the monitoring conditions in a short time, multiple events will be pushed to the client after merging. The request network time consuming multiple pushing events has been reduced, and the performance improves significantly.
Simple and easy -to -use API
Real -time data push provides convenient API for use. Developers can achieve business logic according to the actual scenario, according to the designated collection, query conditions, sorting methods, and restrictions to return quantity. For more detailed explanation, please refer toWeChat Open Documents -Cloud Development Real -time Data Push。
Rich application scenarios
Real -time data push can be applied to many actual business scenarios, such as instant communication, status synchronization, and team collaboration. Whether it is a small program or a small game, you can use the real -time data push of the cloud database to achieve the actual business functions of the relevant scenarios.
1. Instant communication
(1) Mini Program: Live chat room, barrage, etc.
(2) Mini game: district service chat, room chat, private message function, dynamic message, etc.
Idioms Stealing Small Game is a classic instant messaging customer case. It uses real -time data to push the dynamic message reminder of stealing vegetables.
The figure below is the Demo demonstration of the online chat room, which can open the cloud development experience in WeChat developer tools.
2. Status synchronization
(1) Mini Program: Chat prompt Status, friends are entering, friend 1V1 Q & A, etc.
(2) Mini Game: Wuzi Chess, etc.
WeChat Reading One Answers to the Q&A PK section of the applet daily also uses real -time data push, and the countdown, score, results and other states of the two parties in the game will be synchronized in the game.
The figure below is a five -son chess game with real -time data push. The push service is mainly used to synchronize the state of black and white pawn. You can see the source code tutorial for the development of Wuzi Chess here: https://club.cloudbase.net/2019-09-03-share-gomoku/1-1- project outview
3. Team collaboration
(1) Online sharing document
(2) Project management collaboration
The above is the content of sharing for everyone. I hope to help developers better apply real -time data push and add icing on the applet. Finally, welcome to pay attention to the public account of cloud development, and to push the latest functions and high -quality technical articles in cloud development from time to time.
5 Share course video can be viewed here: https://cloud.tencent.com/developer/salon/live-1234
Cloudbase is a cloud -integrated back -end cloud service. It uses the serverless architecture to avoid the tedious server construction and operation and maintenance of mobile applications. At the same time, the static hosting, command line tools (CLI), Flutter SDK and other capabilities provided by cloud development have greatly reduced the threshold for application development. Using cloud development can quickly build applications such as small programs/mini games, H5, Web, mobile APP and other applications.
Technical exchange plus Q group: 601134960
Latest information Pay attention to WeChat public account [Tencent Yunyun Development]