I have to add that I'm a very new Elixir dev, so am trying to get my feet on the ground...
With that said, I've come across the following post, in Japanese/English, that appears to be an example of using a Github project called Erm:
defmodule Amqp do
use Erm
use Amqp.Uri
Erm.addpath("dist/rabbit_common*/ebin")
:io.format("code ~p~n", [:code.lib_dir(:rabbit_common)])
Erm.defrecords_from_hrl("deps/**/amqp_client*/include/amqp_client.hrl")
def start() do
{:ok, re} = Amqp.Uri.parse("amqp://user:pas...@amqp-server-host.example.com")
:io.format("Refields: ~p~n",
[Erm.record_info(:fields, :amqp_params_network)])
:io.format("Re: ~p~n", [re])
{:ok, con} = Amqp.Connection.start(re)
{:ok, chan} = Amqp.Connection.open_channel(con)
ex = Erm.record(:"exchange.declare", [exchange: "my_exchange",
type: "topic"])
Erm.recordl(:"exchange.declare_ok") = Amqp.Channel.call(chan, ex)
q = Erm.record(:"queue.declare", [queue: "my_queue"])
Erm.recordl(:"queue.declare_ok") = Amqp.Channel.call(chan, q)
binding = Erm.record(:"queue.bind", [queue: "my_queue",
exchange: "my_exchange",
routing_key: "key"])
Erm.recordl(:"queue.bind_ok") = Amqp.Channel.call(chan, binding)
payload = "foobar"
publish = Erm.record(:"basic.publish", [exchange: "my_exchange",
routing_key: "key"])
p = Erm.record(:"P_basic", [delivery_mode: 2])
p = Erm.record(:"P_basic", p, [delivery_mode: 2])
Amqp.Channel.cast(chan, publish, Erm.record(:amqp_msg, [props: p,
payload: payload]))
:timer.sleep(10000)
get = Erm.record(:"basic.get", [queue: "my_queue", no_ack: true])
{Erm.recordl(:"basic.get_ok"), content} = Amqp.Channel.call(chan, get)
Erm.recordl(:amqp_msg, [payload: payload2]) = content
:io.format("~p ~p", [payload, payload2])
binding = Erm.record(:"queue.unbind", [queue: "my_queue",
exchange: "my_exchange",
routing_key: "key"])
Erm.recordl(:"queue.unbind_ok") = Amqp.Channel.call(chan, binding)
delete = Erm.record(:"exchange.delete", [exchange: "my_exchange"])
Erm.recordl(:"exchange.delete_ok") = Amqp.Channel.call(chan, delete)
delete = Erm.record(:"queue.delete", [queue: "my_queue"])
Erm.recordl(:"queue.delete_ok") = Amqp.Channel.call(chan, delete)
:ok = Amqp.Channel.close(chan)
:ok = Amqp.Connection.close(con)
end
endIs it better to handle the management of records manually, or is using an abstraction like this a better approach? It seems like using RabbitMQ might require a TON of references that a project like this could eliminate (keep things DRY).