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.
## Summary
Add support for filtering events by type and actor pattern within namespace subscriptions.
## Changes
- Added `SubscriptionFilter` type with `EventTypes` and `ActorPattern` fields
- Added `SubscribeWithFilter` method to `EventBus` for client-side filtering
- Added `SubscribeWithFilter` method to `NATSEventBus` with server-side NATS subject filtering
- Updated `EventBroadcaster` interface to include `SubscribeWithFilter`
- Added comprehensive unit tests for filtering functionality
- Documented filter syntax with examples in code comments
## Implementation Notes
### Event Type Filtering
Subscribers can specify which event types to receive:
```go
filter := SubscriptionFilter{
EventTypes: []string{"OrderPlaced", "OrderShipped"},
}
ch := bus.SubscribeWithFilter("namespace", filter)
```
### Actor Pattern Filtering
Supports prefix matching with wildcard:
```go
filter := SubscriptionFilter{
ActorPattern: "order-*", // matches "order-123", "order-456", etc.
}
```
### 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
Add SubscriptionFilter type and SubscribeWithFilter method to enable
filtering events by type and actor pattern within namespace subscriptions.
- SubscriptionFilter supports event type filtering (e.g., only "OrderPlaced")
- SubscriptionFilter supports actor ID prefix patterns (e.g., "order-*")
- Filters are combined with AND logic
- NATSEventBus uses NATS subjects for server-side filtering when possible
- Comprehensive test coverage for filtering functionality
Closes#21
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
Excellent documentation with clear examples
Well-structured filter logic
Comprehensive unit test coverage (948 lines)
Smart server-side filtering optimization
Issues:
nats_eventbus.go:71-72 Subscription management tracks count per namespace but not which subjects subscribed. Different filters will cause missing events.
eventbus.go:85-98 Wildcard check uses HasSuffix on every match. Consider pre-parsing patterns.
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.
## 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
- Excellent documentation with clear examples
- Well-structured filter logic
- Comprehensive unit test coverage (948 lines)
- Smart server-side filtering optimization
Issues:
1. nats_eventbus.go:71-72 Subscription management tracks count per namespace but not which subjects subscribed. Different filters will cause missing events.
2. eventbus.go:85-98 Wildcard check uses HasSuffix on every match. Consider pre-parsing patterns.
#### 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.
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.
This PR's implementation conflicts with the wildcard subscription support merged in PR #52. The filtering feature needs to be redesigned to:
1. Work with wildcard patterns (the current implementation removed wildcard support)
2. Fix the NATS subscription tracking bug (tracks per namespace, not per subject)
3. Integrate with the metrics system (PR #49)
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.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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