hare v0.2.2 Hare.Core.Exchange

This module defines the Hare.Core.Exchange struct that represents an exchange and holds a channel to interact with it.

Summary

Functions

Declares an exchange on the AMQP server through the given channel, and builds an exchange struct associated to that channel

Builds the default exchange associated to the given channel

It deletes the given exchange

Builds an exchange with the given name associated to the given channel

Publishes a message to the given exchange

Types

chan()
chan() :: Hare.Core.Chan.t
name()
opts()
opts() :: Hare.Adapter.opts
payload()
payload() :: Hare.Adapter.payload
routing_key()
routing_key() :: Hare.Adapter.routing_key
t()
t() :: %Hare.Core.Exchange{chan: chan, name: name}
type()

Functions

declare(chan, name, type \\ :direct, opts \\ [])
declare(chan, name, type, opts) ::
  {:ok, t} |
  {:error, reason :: term}

Declares an exchange on the AMQP server through the given channel, and builds an exchange struct associated to that channel.

It expects the common exchange attributes that will be given to the underlying adapter:

  • name - The name of the exchange to declare
  • type - The type of the exchange as an atom (:fanout, :direct, etc)
  • opts - The exchange options
default(chan)
default(chan) :: t

Builds the default exchange associated to the given channel.

delete(exchange, opts \\ [])
delete(t, opts) :: :ok

It deletes the given exchange.

It expects:

  • exchange - The exchange (and its associated channel) to delete
  • opts - The delete options that will be delegated directly to the adapter
new(chan, name)
new(chan, name) :: t

Builds an exchange with the given name associated to the given channel.

The exchange is supposed to already be declared on the server in order to use it to run functions like publish/4.

Is recommended to always use declare/4 instead of new/2 in order to ensure the exchange is already declared as expected before using it.

publish(exchange, payload, routing_key \\ "", opts \\ [])
publish(t, payload, routing_key, opts) :: :ok

Publishes a message to the given exchange.

It expects the following arguments:

  • exchange - The exchange (and its associated channel) to publish the message to
  • payload - The content of the message to be published
  • routing_key - The routing key
  • opts - The publish options that will be delegated directly to the adapter