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

Link to this type exchange()
exchange() :: String.t()

Exchange name

Link to this type on_callback()
on_callback() :: :ok | {:error, message :: String.t()}

Worker module generic callback result

Link to this type on_deliver()
on_deliver() ::
  :ok |
  {:reject, reason()} |
  {:requeue, reason()} |
  term()

Worker module handle_deliver callback result

Link to this type pattern()
pattern() :: Lapin.Pattern

Module conforming to Lapin.Pattern

Link to this type queue()
queue() :: String.t()

Queue name

Link to this type reason()
reason() :: term()

Reason for message rejection

Link to this type role()
role() :: :consumer | :producer

Channel role

Link to this section Callbacks

Link to this callback handle_cancel(channel_config)
handle_cancel(channel_config :: Lapin.Connection.channel_config()) :: on_callback()

Called when receiving a basic.cancel from the broker.

Link to this callback handle_cancel_ok(channel_config)
handle_cancel_ok(channel_config :: Lapin.Connection.channel_config()) :: on_callback()

Called when receiving a basic.cancel_ok from the broker.

Link to this callback handle_consume_ok(channel_config)
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.

Link to this callback handle_deliver(channel_config, message)
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.

Link to this callback handle_publish(channel_config, message)
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.

Link to this callback handle_return(channel_config, message)
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.

Link to this callback pattern()
pattern() :: pattern()

Returns the pattern for the worker module, defaults to Lapin.Pattern