amqp_pool v0.2.0 AMQPPool.Channel
Manages a single AMQP channel.
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Use a channel. Checking in and out are done automatically.
Link to this section Functions
Link to this function
child_spec(init_arg)
Returns a specification to start this module under a supervisor.
See Supervisor
.
Link to this function
with_channel(func)
Use a channel. Checking in and out are done automatically.
Example:
:ok = AMQPPool.Channel.with_channel(fn channel ->
AMQP.Basic.publish(channel, exchange, routing_key, payload)
end)
Note, if you want to pattern match on the result, do it outside of the with_channel
function. Don't let a pattern match fail in the function supplied to with_channel
.
Here is a more advanced example using with
:
:ok = AMQPPool.Channel.with_channel(fn channel ->
with :ok <- AMQP.Basic.publish(channel, exchange, routing_key, payload),
:ok <- AMQP.Basic.publish(channel, exchange2, routing_key2, payload2) do
:ok
else _ -> :error
end
end)
In the example above, if one of the commands fails, the pattern match *outside* the `with_channel` will fail.