Annotation Interface EventHandlerInterceptor


@Retention(RUNTIME) @Target({METHOD,ANNOTATION_TYPE}) public @interface EventHandlerInterceptor
Annotation marking a method as an event-specific interceptor handler on an AnnotatedEventHandlingComponent.

An annotated interceptor is invoked before every @EventHandler method on the same component instance. Two styles are supported:

  • Before-interceptor — a method with no MessageHandlerInterceptorChain parameter that returns either void or CompletableFuture<Void>. The method runs before the handler; the chain is automatically proceeded after the method returns (or the future completes) normally. If it throws (or the future completes exceptionally), the handler is not invoked.
  • Surround-interceptor — a method that declares a MessageHandlerInterceptorChain parameter and returns a MessageStream. The method controls whether and when the chain is proceeded by calling chain.proceed(event, ctx); it can also short-circuit by returning without calling proceed.

Example before-interceptor:


 @EventHandlerInterceptor
 void audit(EventMessage event) {
     auditLog.record(event.qualifiedName());
 }
 

Example surround-interceptor with short-circuit:


 @EventHandlerInterceptor
 MessageStream<?> filterByTenant(
         EventMessage event,
         MessageHandlerInterceptorChain<EventMessage> chain,
         ProcessingContext ctx
 ) {
     if (!tenantId.equals(event.metaData().get("tenantId"))) {
         return MessageStream.empty();
     }
     return chain.proceed(event, ctx);
 }
 
Since:
5.2.0
Author:
Allard Buijze
See Also: