官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 盐源县| 綦江县| 任丘市| 利津县| 海伦市| 库尔勒市| 郓城县| 通榆县| 哈巴河县| 岳西县| 日照市| 博兴县| 永昌县| 广河县| 芜湖县| 上蔡县| 丹棱县| 毕节市| 沂源县| 乡宁县| 安平县| 静宁县| 太白县| 新密市| 绥芬河市| 灵璧县| 噶尔县| 通江县| 会东县| 福安市| 泸水县| 黑山县| 宝鸡市| 西乌珠穆沁旗| 额尔古纳市| 军事| 濮阳县| 炉霍县| 霍城县| 平乐县| 上思县|