Class DisableMetrics
- All Implemented Interfaces:
DispatchInterceptor, BatchInterceptor, HandlerDecorator, HandlerInterceptor
MessageType.METRICS messages.
This class implements HandlerInterceptor, BatchInterceptor, and DispatchInterceptor,
allowing it to wrap individual message handlers, batch execution by message trackers, or consumer-scoped dispatch
interception directly. When applied as a handler or batch interceptor, it uses an
AdhocDispatchInterceptor to suppress the publication of metrics within the scope of the handler
or batch execution.
Typical usage includes applying this interceptor to consumers that should not emit metrics, such as utility consumers that operate in high-frequency or low-signal environments.
Example Usage
To apply this interceptor, annotate your handler class using@Consumer(batchInterceptors = DisableMetrics.class) or
@Consumer(handlerInterceptors = DisableMetrics.class) or
@Consumer(dispatchInterceptors = DisableMetrics.class):
@Consumer(handlerInterceptors = DisableMetrics.class)
public class OrderHandler {
@HandleEvent
public void on(OrderPlaced event) {
// Any outbound metrics from this handler will be suppressed
}
}
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface HandlerDecorator
HandlerDecorator.MergedDecoratorNested classes/interfaces inherited from interface HandlerInterceptor
HandlerInterceptor.InterceptedHandler -
Field Summary
Fields inherited from interface BatchInterceptor
defaultInterceptorsFields inherited from interface DispatchInterceptor
defaultInterceptors, noOpFields inherited from interface HandlerDecorator
noOpFields inherited from interface HandlerInterceptor
defaultInterceptors -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintercept(Consumer<MessageBatch> consumer, Tracker tracker) Intercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.interceptDispatch(Message message, MessageType messageType, String topic) Intercepts the dispatch of a message before it is serialized and published or locally handled.interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Intercepts the message handling logic.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BatchInterceptor
andThen, shutdownMethods inherited from interface DispatchInterceptor
andThen, modifySerializedMessage, monitorDispatchMethods inherited from interface HandlerDecorator
andThenMethods inherited from interface HandlerInterceptor
wrap
-
Constructor Details
-
DisableMetrics
public DisableMetrics()
-
-
Method Details
-
interceptDispatch
Description copied from interface:DispatchInterceptorIntercepts the dispatch of a message before it is serialized and published or locally handled.You may modify the message or return
nullto block dispatching. Throwing an exception also prevents dispatching.- Specified by:
interceptDispatchin interfaceDispatchInterceptor- Parameters:
message- the message to be dispatchedmessageType- the type of the message (e.g., COMMAND, EVENT, etc.)topic- the target topic or null if not applicable- Returns:
- the modified message, the same message, or
nullto prevent dispatch
-
intercept
Description copied from interface:BatchInterceptorIntercepts the given batch message consumer and returns a decorated version to be invoked by the tracker.- Specified by:
interceptin interfaceBatchInterceptor- Parameters:
consumer- the original consumer that processes theMessageBatchtracker- the tracker invoking this interceptor- Returns:
- a wrapped consumer with additional behavior
-
interceptHandling
public Function<DeserializingMessage, Object> interceptHandling(Function<DeserializingMessage, Object> function, HandlerInvoker invoker) Description copied from interface:HandlerInterceptorIntercepts the message handling logic.The
functionparameter represents the next step in the handling chain— typically the actual message handler. Theinvokerprovides metadata and invocation logic for the underlying handler method.Within this method, an interceptor may:
- Modify the
DeserializingMessagebefore passing it to the handler - Bypass the handler entirely and return a value directly
- Wrap the result after the handler is invoked
Note: Interceptors may return a different
DeserializingMessage, but it must be compatible with a handler method in the same target class. If no suitable handler is found, an exception will be thrown.- Specified by:
interceptHandlingin interfaceHandlerInterceptor- Parameters:
function- the next step in the handler chain (typically the handler itself)invoker- the metadata and execution strategy for the actual handler method- Returns:
- a decorated function that wraps handling behavior
- Modify the
-