Architecting Cloud Native Applications
上QQ阅读APP看书,第一时间看更新

Example – component anatomy

The following example shows how the component in the diagram at the beginning of this pattern could be configured and deployed using function-as-a-service, following the patterns discusses throughout this chapter. There is a function for publishing events following the Database-First Event Sourcing variant, a function for consuming events, and two RESTful functions for implementing a command and a query. Each function is its own independently scalable deployment unit, yet they are conveniently managed together as a whole. We will recognize this pattern as we dive into the higher-order patterns in Chapter 4, Boundary Patterns and Chapter 5, Control Patterns.

functions:
command:
handler: handler.command
events:
- http:
path: items
method: post
- http:
path: items/{id}
method: put
environment:
TABLE_NAME:
Ref: Table
query:
handler: handler.query
events:
- http:
path: items/{id}
method: get
environment:
TABLE_NAME:
Ref: Table
publish:
handler: handler.publish
events:
- stream:
type: dynamodb
arn:
Fn::GetAtt:
- Table
- StreamArn
batchSize: 100
startingPosition: TRIM_HORIZON
environment:
STREAM_NAME:
Ref: Stream
subscribe:
handler: handler.consume
events:
- stream:
type: kinesis
arn:
Fn::GetAtt:
- Stream
- Arn
batchSize: 100
startingPosition: TRIM_HORIZON
environment:
STREAM_NAME:
Ref: Stream
TABLE_NAME:
Ref: Table