Flux AMQP v0.0.5 FluxAMQP.Consumer behaviour View Source

Module responsible to consume AMQP messages.

The main approach to consume is done by defining a module which extends FluxAMQP.Consumer and implements routing_keys/0 and consume/3 functions:

defmodule MyApp.AMQP.Consumer do
  use FluxAMQP.Consumer

  @impl FluxAMQP.Consumer
  def routing_keys do
    [
      "route.example",
      {"another.route.example", "amq.direct"}
    ]
  end

  @impl FluxAMQP.Consumer
  def consume(channel, delivery_tag, routing_key, payload) do
    # Handle message
  end
end

Then, set the connection as a worker child on your application:

defmodule MyApp.Application do
  use Application

  @impl Application
  def start(_type, _args) do
    import Supervisor.Spec

    children = [
      worker(MyApp.AMQP.Consumer, [])
    ]

    opts = [strategy: :one_for_one]

    Supervisor.start_link(children, opts)
  end
end

If routing_keys/0 returns an empty list, FluxAMQP will try to extract the routing keys from the application configuration.

Link to this section Summary

Link to this section Callbacks

Link to this callback

consume(channel, payload, meta)

View Source
consume(channel :: AMQP.Channel.t(), payload :: String.t(), meta :: map()) ::
  any()
Link to this callback

routing_keys()

View Source
routing_keys() :: [String.t() | {String.t(), String.t()}]