# AMQP RPC Client/Server templates [![Build Status](]( [![](]( 

**Warning!** POC quality!

## Goals
 - Reduce boilerplate
 - Handle reconnects
 - Messages housekeeping 
 - Logging
 - Monitoring
 - Use [fuse](
 - Content negotiation

### Fuse
[Fuse]( helps reduce latency when something goes wrong with RabbitMQ or RPC server side by breaking circuit and returning immideately. Fuse can be configured via `fuse_name` and `fuse_opts` keys. We trying to maintain sensible default for those. 

### Monitoring/Instrumenting
Clients can be instrumented using built-in metrics plugins. Currenly [implemented](
 - ETS-backed plugin (default)
 - [Prometheus]( plugin.

## Example

Below is 'classic' RPC example from [RabbitMQ tutorials](
rewritten using amqp_rpc:


defmodule Fibonacci do
  use AMQP.RPC.Client, [exchange: "",
                        queue: "rpc_queue"]

  def fib(n, timeout \\ @timeout) do
    rpc(%{command_name: "fib",
          args: n}, timeout)


defmodule FibonacciServer do
  use AMQP.RPC.Server, [exchange: "",
                        queue: "rpc_queue",
                        commands: [:fib]]

  ## adapted from

  def fib(0), do: 0

  def fib(n)
  when is_number(n) and n > 0,
    do: fib(n, 1, 0, 1)

  def fib(_), do: [error: "positive integers only"]

  def fib(n, m, _prev_fib, current_fib)
  when n == m,
    do: current_fib

  def fib(n, m, prev_fib, current_fib),
    do: fib(n, m+1, current_fib, prev_fib + current_fib)


## Installation

[Available in Hex](, the package can be installed as:

  1. Add `amqp_rpc` to your list of dependencies in `mix.exs`:

    def deps do
      [{:amqp_rpc, "~> 0.0.7"}]

  2. Ensure `amqp_rpc` is started before your application:

    def application do
      [applications: [:amqp_rpc]]