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

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 1Getting 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.

主站蜘蛛池模板: 化州市| 武威市| 阜阳市| 辉南县| 和顺县| 舟曲县| 明光市| 巴青县| 南宁市| 保定市| 旺苍县| 靖州| 东乡县| 鹤壁市| 大荔县| 宝应县| 蓬溪县| 万源市| 泗阳县| 广饶县| 桐梓县| 应用必备| 射阳县| 汪清县| 广灵县| 桦甸市| 青浦区| 日喀则市| 塔河县| 满洲里市| 德化县| 嵊州市| 原平市| 泰和县| 奉化市| 崇信县| 新安县| 上虞市| 台南县| 仲巴县| 濮阳市|