[Issue #21] Add namespace event filtering #51
Reference in New Issue
Block a user
Delete Branch "issue-21-namespace-event-filtering"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add support for filtering events by type and actor pattern within namespace subscriptions.
Changes
SubscriptionFiltertype withEventTypesandActorPatternfieldsSubscribeWithFiltermethod toEventBusfor client-side filteringSubscribeWithFiltermethod toNATSEventBuswith server-side NATS subject filteringEventBroadcasterinterface to includeSubscribeWithFilterImplementation Notes
Event Type Filtering
Subscribers can specify which event types to receive:
Actor Pattern Filtering
Supports prefix matching with wildcard:
Server-Side Filtering
For NATSEventBus, single event type filters use NATS subject-based routing for efficiency. Multiple event types or actor patterns are filtered client-side.
AND Logic
When both filters are specified, events must match all criteria.
Closes #21
AI Code Review
This is an automated review generated by the code-reviewer agent.
Summary
PR adds namespace event filtering with event type and actor pattern support. Implementation is well-structured with comprehensive tests. Server-side NATS filtering for single event types is a smart optimization. Found one critical bug in NATS subscription management and several areas for improvement.
Findings
Code Quality
Issues:
Potential Bugs
CRITICAL nats_eventbus.go:71-108 Subscription management broken. Example: First subscriber with EventTypes:[OrderPlaced] creates NATS sub. Second subscriber with EventTypes:[UserCreated] sees count>0, skips NATS subscription. Second subscriber NEVER receives events. Fix: Track subscriptions per subject not per namespace.
BREAKING CHANGE nats_eventbus.go:161 Subject format changed from aether.events.{ns} to aether.events.{ns}.{type}. Old subscribers incompatible. Needs migration path.
Test Coverage
Excellent unit tests but missing NATSEventBus integration tests and subscription management tests.
Verdict
BLOCKING ISSUES
Critical bug will cause lost events. Subject change breaks compatibility.
Recommendations: Fix subscription tracking with map[subject]*nats.Subscription. Add NATSEventBus integration tests. Document migration path.
This PR's implementation conflicts with the wildcard subscription support merged in PR #52. The filtering feature needs to be redesigned to:
Closing this PR. The filtering feature should be re-implemented in a new PR that builds on the current main branch with wildcards and metrics support.
Pull request closed