Skip to content

FEATURE: Support Query filters of subscribers - #4

Merged
bwaidelich merged 2 commits into
mainfrom
filtered-reads
Nov 12, 2026
Merged

bwaidelich merged 2 commits into
mainfrom
filtered-reads

Conversation

@bwaidelich

@bwaidelich bwaidelich commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

Implements the 2.0 adapter contract from bwaidelich/subscription-engine#20. Subscribers can declare a Query as filter.

Subscriber::create(
    id: 'orders',
    handler: $handler,
    filter: Query::fromItems(QueryItem::create(eventTypes: ['OrderPlaced', 'OrderCancelled'])),
);
read(start, ReadOptions)
  eventStore->read(filter ?? Query::all(), from: start, limit: limit)
  stop at the first event above upTo     // if set, the read is ordered
matches(filter, sequencedEvent)          // for runs with several subscriptions
  filter->matchesEvent(sequencedEvent->event)

Query items with onlyLastEvent throw an InvalidArgumentException, because matches() can't apply them.

-"wwwision/subscription-engine": "^1 || ^2"
+"wwwision/subscription-engine": "^2"   // ReadOptions doesn't exist in 1.x

The README example is runnable, links the guides, and documents filtered subscribers.

Evidence

  • Before: against core with FEATURE: Filtered reads for subscribers subscription-engine#20, the adapter fatals (old read() signature, no matches())
    After: composer test green, 10 tests:
    events: Odd Even Odd Even
    read(1, filter: Even)            → [2, 4]
    read(1, limit: 2, filter: Odd)   → [1, 3]   // limit counts matching events
    read(1, upTo: 3, filter: Even)   → [2]
    matches(Even, each event)        → [false, true, false, true]
    filter of another type / onlyLastEvent → InvalidArgumentException
    
  • End-to-end on PostgreSQL 17 with wwwision/dcb-eventstore-doctrine and the worker API:
    events: A B A A B A A A, subscriber "only-b" filters on B
    handled: {"all":[1,2,3,4,5,6,7,8],"only-b":[2,5]}
    all ACTIVE 8, only-b ACTIVE 8
    
  • The integration tests of subscription-engine-worker are green against this branch.

Merge Danger

Door: two-way

Nothing is tagged yet.

Blast Radius: consumers

A release requires subscription engine 2.x. The worker's dev-main dependency picks this up on merge, so merge it together with bwaidelich/subscription-engine#20.

Implements the `ReadOptions` based `read()` of subscription engine 2.0
and `matches()`. Subscribers can declare a `Query` as filter, items with
`onlyLastEvent` are rejected, as `matches()` can't apply them.

Requires subscription engine 2.x, as `ReadOptions` doesn't exist in 1.x.
@bwaidelich bwaidelich changed the title Filtered reads FEATURE: Support Query filters of subscribers Nov 12, 2026
@bwaidelich
bwaidelich merged commit 40a5ffe into main Nov 12, 2026
@bwaidelich
bwaidelich deleted the filtered-reads branch November 12, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant