- JavaScript Cloud Native Development Cookbook
- John Gilbert
- 350字
- 2021-07-16 18:03:31
How it works...
In this recipe, we are implementing an offline-first solution where the ReactJS client application stores all changes in local storage and then synchronizes the data to a Cognito dataset in the cloud when connectivity is available. This scenario is very common in mobile applications where the mobile application may not always be connected. An AWS Cognito dataset is associated with a specific user in an AWS Identity Pool. In this recipe, the identity pool supports unauthenticated users. Anonymous access is another common characteristic of mobile applications.
The bare bones ReactJS application is implemented in the ./index.html file. It contains a form for the user to enter data. The Save button saves the form's data to local storage via the Cognito SDK. The Synchronize button uses the SDK to send the local data to the cloud. In a typical application, this synchronization would be triggered behind the scenes by events in the normal flow of the application, such as on save, on load, and before exit. In the Creating a materialized view in a Cognito Dataset recipe, we show how synchronizing will also retrieve data from the cloud.
Cognito's change data capture feature is implemented via AWS Kinesis. Therefore, we create a Kinesis stream called CognitoStream that is dedicated to our Cognito datasets. The trigger function is a stream processor that is consuming sync records from this stream. The stream processor's recordToSync step extracts the domain object from each sync record, where it is stored as a JSON string. The toEvent step wraps the domain object in the standard event format, as discussed in the Creating an event stream and publishing an event recipe in Chapter 1, Getting Started with Cloud-Native. Finally, the event is written to the stream specified by the STREAM_NAME environment variable. Note that the trigger function is similar to the event-first variant. It just needs to execute quickly and leave as little to chance as possible. We write the event to a single resource, the highly available, fully managed cloud-native event stream, and trust that the downstream services will eventually consume the event.
- 構(gòu)建運(yùn)營級(jí)IPv6網(wǎng)絡(luò)
- 通信專業(yè)實(shí)務(wù):動(dòng)力與環(huán)境
- Photoshop移動(dòng)UI界面設(shè)計(jì)實(shí)用教程
- 想到做到:Android開發(fā)關(guān)鍵技術(shù)與精彩案例
- 集成電路靜態(tài)時(shí)序分析與建模
- 云存儲(chǔ)解析
- 6G關(guān)鍵技術(shù)權(quán)威指南
- 雷達(dá)系統(tǒng)及其信息處理
- 電信行業(yè)競爭分析方法與實(shí)踐
- 3G知識(shí)問答
- 現(xiàn)代電子戰(zhàn)系統(tǒng)導(dǎo)論(第二版)
- 高速信號(hào)傳輸工程化技術(shù):概念與方法
- 水聲信道常數(shù)模盲均衡:理論、算法與仿真
- 空間相干激光通信技術(shù)(精裝版)
- 電視機(jī)、顯示器集成電路應(yīng)用與檢修手冊(cè)