ListenersExamples

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: venue

Concert 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: artist

Trade-off: listeners give synchronous counters; Projection Examples use async increment: — often better under high concurrency.


More examples

ExamplePattern
Concert AppFull domain with projections as primary read path
Intent ExamplesEvents that trigger listeners
Projection ExamplesAsync alternative for counters

Next steps