Listener Examples
Match scoring
# listeners/scoring.listeners.causet
listeners:
- on: POINTS_AWARDED
where: event.payload.apply_to_match
resolve:
match: lookup(match, event.payload.match_id)
mutate:
- op: add
path: /stats/home_score
value: event.payload.delta
on: match
- op: set
path: /last_scored_at
value: event.ts
on: match
- on: MATCH_COMPLETED
resolve:
venue: lookup(venue, event.payload.venue_id)
mutate:
- op: add
path: /completed_match_count
value: 1
on: venue
- op: push
path: /recent_match_ids
value: event.entity_id
on: venueConcert app — follower counter
Sync artist.follower_count in the same commit as FOLLOW_ARTIST:
# listeners/follow.listeners.causet
listeners:
- on: ARTIST_FOLLOWED
resolve:
artist: lookup(artist, event.payload.artist_id)
mutate:
- op: add
path: /follower_count
value: 1
on: artist
- on: ARTIST_UNFOLLOWED
resolve:
artist: lookup(artist, event.payload.artist_id)
mutate:
- op: sub
path: /follower_count
value: 1
on: artistTrade-off: listeners give synchronous counters; Projection Examples use async increment: — often better under high concurrency.
More examples
| Example | Pattern |
|---|---|
| Concert App | Full domain with projections as primary read path |
| Intent Examples | Events that trigger listeners |
| Projection Examples | Async alternative for counters |
Next steps
- Defining Listeners —
where,resolve, supported ops - Best Practices — when not to use listeners