- JavaScript Cloud Native Development Cookbook
- John Gilbert
- 318字
- 2021-07-16 18:03:30
How it works...
In this recipe, we implement a command function that would be part of a Backend For Frontend service. Following the Event Sourcing pattern, we make this command atomic by only writing to a single resource. In many scenarios, such as the authoring of data, we need to write data and make sure it's immediately available for reading. In these cases, the database-first variant is most appropriate. The command just needs to execute quickly and leave as little to chance as possible. We write the domain object to the highly available, fully-managed cloud-native database and trust that the database's change data capture mechanism will handle the next step.
In this recipe, the database is DynamoDB and the change data capture mechanism is DynamoDB Streams. The trigger function is a stream processor that is consuming events from the specified DynamoDB stream. We enable the stream by adding the StreamSpecification to the definition of the table.
The stream processor logic 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. The record.eventID generated by DynamoDB is reused as the domain event ID, the database trigger's record.eventName is translated into the domain event type, the domain object ID is used as partitionKey, and useful tags are adorned. The old and new values of the domain object are included in the event so that downstream services can calculate a delta however they see fit.
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.
- 5G無線接入網(wǎng)架構(gòu)及關(guān)鍵技術(shù)
- 5G承載關(guān)鍵技術(shù)與規(guī)劃設(shè)計(jì)
- 通信系統(tǒng)仿真設(shè)計(jì)與應(yīng)用
- 電子產(chǎn)品零部件檢測(cè)與選用技能演練
- 機(jī)載激光雷達(dá)基礎(chǔ)原理與應(yīng)用
- 液晶顯示器維修實(shí)踐技術(shù)
- IPv6網(wǎng)絡(luò)部署實(shí)戰(zhàn)
- 高速數(shù)字電路設(shè)計(jì)入門
- Android嵌入式應(yīng)用開發(fā)
- 通信對(duì)抗偵察信息處理技術(shù)
- 光網(wǎng)絡(luò)信息傳輸技術(shù)
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)
- 云計(jì)算安全
- DSP控制器原理與技術(shù)應(yīng)用
- 從1G到5G:移動(dòng)通信如何改變世界