Handling¶
Handlers what actually consume message envelopes. When the router routes an
envelope and returns a handler instance to the Consumer
, the
Consumer
executes the handler by invoking its pre_handle()
,
handle()
, and post_handle()
methods respectively.
Handler¶
-
class
rabbitleap.handling.
Handler
(envelope, **kwargs)[source] Base class for envelope handlers.
envelope
is a reference to the given message envelope.Subclasses MUST implement
handle()
method.Methods:
initialize()
: initialization hook used to initialize the handler with kwargs.pre_handle()
: pre handling method invoked beforehandle()
.handle()
: to be implemented by the subclasses for the actual handling logic.post_handle()
: post handling method invoked afterhandle()
.
-
Handler.
initialize
(**kwargs)[source] Initialize handler.
This method is an initialization hook for the handler.
-
Handler.
pre_handle
()[source] Pre handle message envelope.
This method is invoked by the
Consumer
before invokinghandle()
. It’s meant for validation and preparation before the actual handling.Handler
subclasses can override this method to add pre handling logic.
-
Handler.
handle
()[source] Handle message envelope.
This method is invoked by the
Consumer
after invokingpre_handle()
. The actual envelope handling should happen in this method.Handler
subclasses MUST implement this method.
-
Handler.
post_handle
()[source] Post handle message envelope.
This method is invoked by the consumer after invoking
handle()
. It’s meant for clean up and logging after the actual handlingHandler
subclasses can override this method to add post handling logic.
Message Handler¶
-
class
rabbitleap.handling.
MessageHandler
(consumer, envelope, **kwargs)[source] Bases:
rabbitleap.handling.Handler
Message handler.
This class extens the
Handler
class with methods used to reject and skip envelopes, also report handling error. It hold a reference to:class:.Consumer instance which does the execution.Methods:
initialize()
: initialization method, a hook initialize the handler with kwargs.pre_handle()
: pre handling method invoked beforehandle()
.handle()
: overridden by the subclass implementing the handling logic.post_handle()
: post handling method invoked afterhandle()
.error()
: a shortcut forConsumer.error()
to raiseHandlingError
exception.abort()
: a shortcut forConsumer.abort()
to reject message.skip()
: a shortcut forConsumer.skip()
to skip message handling.
-
MessageHandler.
abort
(reason=None)[source] Abort handling the message.
This method is a shortcut for
Consumer.abort()
.NOTE: when called inside the handler, the handler should re-raise
AbortHandling
exception to the consumer if the exception is handled inside it.Parameters: reason (str) – Reason for aborting handling the message.
-
MessageHandler.
error
(error_msg=None)[source] Raise
HandlingError
exception.This method is a shortcut for
Consumer.error()
.Raise: HandlingError
when called.NOTE: when called inside the handler, the handler should re-raise
HandlingError
exception to the consumer, in case the exception is handled inside.Parameters: error_msg (str) – Error message.
-
MessageHandler.
skip
(reason=None)[source] Skip handling the message.
This method is a shortcut for
Consumer.skip()
.NOTE: when called inside the handler, the handler should re-raise
SkipHandling
exception to the consumer if the exception is handled inside it.Parameters: reason (str) – Reason for skipping handling the message.