Annotation Interface CommandHandlerInterceptor
Annotation marking a method as a command-specific interceptor handler on an
AnnotatedCommandHandlingComponent.
An annotated interceptor is invoked before every @CommandHandler method on the same component
instance. Two styles are supported:
- Before-interceptor — a method with no
MessageHandlerInterceptorChainparameter that returns eithervoidorCompletableFuture<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
MessageHandlerInterceptorChainparameter and returns aMessageStream. The method controls whether and when the chain is proceeded by callingchain.proceed(command, ctx); it can also short-circuit by returning without calling proceed.
Example before-interceptor:
@CommandHandlerInterceptor
void audit(CommandMessage command) {
auditLog.record(command.qualifiedName());
}
Example surround-interceptor with short-circuit:
@CommandHandlerInterceptor
MessageStream<?> filterByTenant(
CommandMessage command,
MessageHandlerInterceptorChain<CommandMessage> chain,
ProcessingContext ctx
) {
if (!tenantId.equals(command.metaData().get("tenantId"))) {
return MessageStream.failed(new AccessDeniedException("Wrong tenant"));
}
return chain.proceed(command, ctx);
}
- Since:
- 5.2.0
- Author:
- Allard Buijze
- See Also: