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.
envelopeis 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
Consumerbefore invokinghandle(). It’s meant for validation and preparation before the actual handling.Handlersubclasses can override this method to add pre handling logic.
-
Handler.handle()[source] Handle message envelope.
This method is invoked by the
Consumerafter invokingpre_handle(). The actual envelope handling should happen in this method.Handlersubclasses 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 handlingHandlersubclasses can override this method to add post handling logic.
Message Handler¶
-
class
rabbitleap.handling.MessageHandler(consumer, envelope, **kwargs)[source] Bases:
rabbitleap.handling.HandlerMessage handler.
This class extens the
Handlerclass 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 raiseHandlingErrorexception.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
AbortHandlingexception 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
HandlingErrorexception.This method is a shortcut for
Consumer.error().Raise: HandlingErrorwhen called.NOTE: when called inside the handler, the handler should re-raise
HandlingErrorexception 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
SkipHandlingexception to the consumer if the exception is handled inside it.Parameters: reason (str) – Reason for skipping handling the message.