Where
Filters events delivered to a handler method.
To apply filtering to an event handler method, annotate the first parameter of the method.
For example, the following method would be invoked only if the owner of the created project is [email protected]
:
@Subscribe
void on(@Where(field = "owner.email", equals = "[email protected]") ProjectCreated e) { ... }
Content copied to clipboard
Annotations for handler methods which support @Where
should be marked with AcceptsFilters.
Filtering Events by a Field Value
If a field filter is defined, only the events matching this filter are passed to the handler method.
A single class may define a number of handler methods with different field filters. Though, all the field filters must target the same field. For example, this event handling is valid:
@Subscribe
voidonExpired(@Where(field = "subscription.status", equals = "EXPIRED")
UserLoggedIn event) {
// Handle expired subscription.
}
@Subscribe
voidonInactive(@Where(field = "subscription.status", equals = "INACTIVE")
UserLoggedIn event) {
// Handle inactive subscription.
}
@Subscribe
void on(UserLoggedIn event) {
// Handle other cases.
}
Content copied to clipboard
And this one is not:
@Subscribe
voidonExpired(@Where(field = "subscription.status", equals = "EXPIRED")
UserLoggedIn event) {
}
@Subscribe
voidonUnknownBilling(@Where(field = "payment_method.status", equals = "UNSET")
UserLoggedIn event) {
// Error, different field paths used in the same class for the same event type.
}
Content copied to clipboard