- JavaScript Cloud Native Development Cookbook
- John Gilbert
- 172字
- 2021-07-16 18:03:29
How it works...
In this recipe, we implement a command function called submit 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 some scenarios, such as initiating a long-lived business process or tracking user clicks, we only need to fire-and-forget. In these cases, the event-first variant is most appropriate. The command just needs to execute quickly and leave as little to chance as possible. We write the event to the highly available, fully-managed cloud-native event stream and trust that the downstream services will eventually consume the event.
The 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 event type is specified, the domain object ID is used as the partitionKey, and useful tags are adorned. Finally, the event is written to the stream specified by the STREAM_NAME environment variable.