gen_rmq v0.2.0 GenRMQ.Publisher behaviour

A behaviour module for implementing the RabbitMQ publisher

Summary

Functions

Returns a specification to start this module under a supervisor

Starts GenRMQ.Publisher with given callback module linked to the current process

Callbacks

Invoked to provide publisher configuration

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

publish(publisher, message, routing_key \\ "", headers \\ [])

Specs

publish(publisher :: Atom.t | Pid.t, message :: Binary.t, routing_key :: String.t, headers :: Keyword.t) :: :ok

Publishes given message

publisher - name or PID of the publisher

message - raw payload to deliver

routing_key - optional routing key to set for given message

headers - optional headers to set for given message

Examples:

GenRMQ.Publisher.publish(TestPublisher, "{"msg": "hello"})
start_link(module, options \\ [])

Specs

start_link(module :: Module.t, options :: Keyword.t) ::
  {:ok, Pid.t} |
  {:error, Any.t}

Starts GenRMQ.Publisher with given callback module linked to the current process

module- callback module implementing GenRMQ.Publisher behaviour

Options

  • :name - used for name registration

Return values

If the publisher is successfully created and initialized, this function returns {:ok, pid}, where pid is the PID of the publisher. If a process with the specified publisher name already exists, this function returns {:error, {:already_started, pid}} with the PID of that process.

Examples:

GenRMQ.Publisher.start_link(TestPublisher, name: :publisher)

Callbacks

init()

Specs

init :: [exchange: String.t, uri: String.t, app_id: Atom.t]

Invoked to provide publisher configuration

Return values

Mandatory:

uri - RabbitMQ uri

exchange - the name of the target exchange. If does not exist it will be created

Optional:

app_id - publishing application ID

Examples:

def init() do
  [
    exchange: "gen_rmq_exchange",
    uri: "amqp://guest:guest@localhost:5672"
    app_id: :my_app_id
  ]
end