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, "~> 0.10.0"}]
end
- Ensure
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
@routing_key "amqp-service"
def start_link(conn, initial \\ nil, opts \\ []) do
Freddy.RPC.Client.start_link(__MODULE__, conn, [], initial, opts)
end
def ping(client \\ __MODULE__) do
Freddy.RPC.Client.request(client, @routing_key, %{type: "ping"})
end
end
- Put 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
end
- You can now use your client:
case AMQPService.ping() do
{:ok, resp} ->
IO.puts "Response: #{inspect response}"
{:error, reason} ->
IO.puts "Something went wrong: #{inspect reason}"
end