Event handlers
Event handler objects are singletons, registered into one (or even more) EventProcessors. Event handler methods must satisfy
the following requirements:
- Annotated with
@EventHandler - The first parameter is the event payload, can be an instance of any type
- The second parameter is an
EventContext - The method must return
Mono<Void>
In case of Spring Boot configuration, using @EventHandlerBean class level annotation is possible. An instance of the class will be a singleton
Spring bean. The event processor, attached the handler object to, can be defined with the annotation.
@EventHandlerBean(processorId = "email-sender")
public class EmailSender {
@EventHandler
public Mono<Void> handle(UserRegistrationRequested event, EventContext context) {
return mailService.sendRegistrationMail(event.getUserId(), event.getEmail(), event.getUsername());
}
}
Event processors
Event processors can be created programmatically, or implicitly by the @EventHandlerBean annotation. All event handler methods a specific
event processor is responsible for are executed parallel with the same event. See AnnotationAwareEventMessageDispatcher.