Lab 07: CQRS Patterns
Overview
Step 1: Command and Query Interfaces
package cqrs
import "context"
// Command: intent to change state
// Naming: verb + noun (CreateUser, PlaceOrder, CancelOrder)
type Command interface {
CommandName() string
}
// Query: request for data, no side effects
// Naming: noun phrase (GetUser, ListOrders, SearchProducts)
type Query interface {
QueryName() string
}
// Handler types
type CommandHandler func(ctx context.Context, cmd Command) error
type QueryHandler func(ctx context.Context, query Query) (interface{}, error)
// Middleware: wraps a handler
type CommandMiddleware func(next CommandHandler) CommandHandler
type QueryMiddleware func(next QueryHandler) QueryHandlerStep 2: CommandBus with Middleware Chain
Step 3: Three Middleware Handlers
Step 4: QueryBus
Step 5: Domain Commands and Queries
Step 6: In-Process Event Bus
Step 7: Saga Orchestrator
Step 8: Capstone — CommandBus with 3 Middleware
Summary
Component
Interface
Role
Last updated
