Freddy
RPC protocol over RabbitMQ. In development stage.
Installation
The package can be installed as:
Add
freddyto your list of dependencies inmix.exs:def deps do [{:freddy, github: "salemove/ex_freddy"}] endEnsure
freddyis started before your application:def application do [applications: [:freddy]] end
Usage
Create Freddy connection:
{:ok, conn} = Freddy.Conn.start_link()Create RPC Client:
defmodule AMQPService do use Freddy.RPC.Client @config [routing_key: "amqp-service"] def start_link(conn, initial \\ nil, opts \\ []) do Freddy.RPC.Client.start_link(__MODULE__, conn, @config, initial, opts) end def ping(client) do Freddy.RPC.Client.request(client, %{type: "ping"}) end endPut both connection and service under supervision tree (in this case we’re registering connection process and RPC client process under static names):
defmodule MyApp do use Application def start(_type, _args) do import Supervisor.Spec children = [ worker(Freddy.Conn, [[], [name: Freddy.Conn]]), worker(AMQPService, [Freddy.Conn, nil, [name: AMQPService]]) ] opts = [strategy: :one_for_one, name: MyApp.Supervisor] Supervisor.start_link(children, opts) end endYou can now use your client:
case AMQPService.ping(AMQPService) do {:ok, resp} -> IO.puts "Response: #{inspect response}" {:error, reason} -> IO.puts "Something went wrong: #{inspect reason}" end