gen_rmq v2.1.0 GenRMQ.Publisher behaviour View Source
A behaviour module for implementing the RabbitMQ publisher
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Publishes given message
Starts GenRMQ.Publisher
with given callback module linked to the current
process
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
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
metadata
- optional metadata to set for given message. Keys that
are not allowed in metadata are moved under the `:headers`
field. Do not include a `:headers` field here: it will be
created automatically with all non-standard keys that you have
provided.
Examples:
GenRMQ.Publisher.publish(TestPublisher, "{"msg": "hello"})
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)
Link to this section Callbacks
init()
View Sourceinit() :: [ exchange: GenRMQ.Binding.exchange(), uri: String.t(), app_id: atom(), enable_confirmations: boolean(), max_confirmation_wait_time: integer() ]
Invoked to provide publisher configuration
Return values
Mandatory:
uri
- RabbitMQ uri
exchange
- name or {type, name}
of the target exchange. If it does not exist, it will be created.
For valid exchange types see GenRMQ.Binding
.
Optional:
app_id
- publishing application ID
enable_confirmations
- activates publishing confirmations on the channel. Confirmations are disabled by default.
max_confirmation_wait_time
- maximum time in milliseconds to wait for a confirmation. By default it is 5_000 (5s).
Examples:
def init() do
[
exchange: "gen_rmq_exchange",
uri: "amqp://guest:guest@localhost:5672"
app_id: :my_app_id,
enable_confirmations: true,
max_confirmation_wait_time: 5_000
]
end