errol v0.1.0 Errol.Consumer.Server View Source

GenServer that creates a queue, binds it to a given routing_key and consumes messages from that queue.

The preferred way of spinning up consumer this is through Errol.Wiring.consume/3 when declaring your Wiring, but you can also use this module to start them on your own.

Examples

iex> {:ok, connection} = AMQP.Connection.open()
iex> {:ok, _pid} = Errol.Consumer.Server.start_link(name: :queue_consumer, queue: "queue_name", routing_key: "my.routing.key", callback: fn _message -> :ok end, exchange: {"/", :topic}, connection: connection)
iex> Errol.Consumer.Server.unbind(:queue_consumer)
:ok

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor

Creates a queue, binds it to a given routing_key and Starts a process that consumes messages from that queue

Unbinds the given process from the rabbitmq queue it is subscribed to and shuts down the process

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function start_link(args) View Source
start_link(options :: keyword()) :: {:ok, pid()} | {:error, reason :: atom()}

Creates a queue, binds it to a given routing_key and Starts a process that consumes messages from that queue.

It expects the following arguments:

  • name A name for the process.
  • queue A name for the queue that will be created.
  • routing_key: A rabbitmq compatible routing key (e.g. my.routing.key).
  • callback: A function with arity of 1.
  • exchange: The expected format is {exchange_path, exchange_type}. exchange_type can be :topic, :fanout or :direct.
  • connection: You can create a connection through AMQP.Connection.open/1.
Link to this function unbind(consumer_name) View Source
unbind(consume_name :: atom() | pid()) :: :ok

Unbinds the given process from the rabbitmq queue it is subscribed to and shuts down the process.