lapin v0.1.5 Lapin.Worker behaviour
Lapin Worker behaviour
To Implement a custom Lapin.Worker behaviour define a module:
defmodule MyApp.MyWorker do
use Lapin.Worker
[... callbacks implementation ...]
end
A custom Lapin.Pattern module can be specified using the pattern option:
defmodule MyApp.MyWorker do
use Lapin.Worker, pattern: MyApp.MyPattern
[... callbacks implementation ...]
end
Check out the Lapin.Pattern submodules for a number of implementantions of
common interaction patterns.
Link to this section Summary
Types
Exchange name
Worker module generic callback result
Worker module handle_deliver callback result
Module conforming to Lapin.Pattern
Queue name
Reason for message rejection
Channel role
Callbacks
Called when receiving a basic.cancel from the broker
Called when receiving a basic.cancel_ok from the broker
Called when receiving a basic.consume_ok from the broker
Called when receiving a basic.deliver from the broker
Called when completing a basic.publish with the broker
Called when receiving a basic.return from the broker
Returns the pattern for the worker module, defaults to Lapin.Pattern
Link to this section Types
Exchange name
Worker module generic callback result
on_deliver() :: :ok | {:reject, reason()} | {:requeue, reason()} | term()
Worker module handle_deliver callback result
Module conforming to Lapin.Pattern
Queue name
Reason for message rejection
Channel role
Link to this section Callbacks
handle_cancel(channel_config :: Lapin.Connection.channel_config()) :: on_callback()
Called when receiving a basic.cancel from the broker.
handle_cancel_ok(channel_config :: Lapin.Connection.channel_config()) :: on_callback()
Called when receiving a basic.cancel_ok from the broker.
handle_consume_ok(channel_config :: Lapin.Connection.channel_config()) :: on_callback()
Called when receiving a basic.consume_ok from the broker.
This signals successul registration as a consumer.
handle_deliver(channel_config :: Lapin.Connection.channel_config(), message :: Lapin.Message.t()) :: on_deliver()
Called when receiving a basic.deliver from the broker.
Return values from this callback determine message acknowledgement:
:ok: Message was processed by the consumer and should be removed from queue{:requeue, reason}: Message was not processed and should be requeued{:reject, reason}: Message was not processed but should NOT be requeued
Any other return value, including a crash in the callback code, has the same
effect as {:reject, reason}: it rejects the message WITHOUT requeueing. The
reason term can be used by the application to signal the reason of rejection
and is logged in debug.
handle_publish(channel_config :: Lapin.Connection.channel_config(), message :: Lapin.Message.t()) :: on_callback()
Called when completing a basic.publish with the broker.
Message transmission to the broker is successful when this callback is called.
handle_return(channel_config :: Lapin.Connection.channel_config(), message :: Lapin.Message.t()) :: on_callback()
Called when receiving a basic.return from the broker.
THis signals an undeliverable returned message from the broker.
Returns the pattern for the worker module, defaults to Lapin.Pattern