项目作者: deadtrickster

项目描述 :
RPC Client/Server for amqp Elixir library
高级语言: Elixir
项目地址: git://github.com/deadtrickster/amqp_rpc.git
创建时间: 2016-07-30T00:33:02Z
项目社区:https://github.com/deadtrickster/amqp_rpc

开源协议:MIT License

下载


AMQP RPC Client/Server templates Build Status Hex.pm

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

Example

Below is ‘classic’ RPC example from RabbitMQ tutorials
rewritten using amqp_rpc:

Client:

  1. defmodule Fibonacci do
  2. use AMQP.RPC.Client, [exchange: "",
  3. queue: "rpc_queue"]
  4. def fib(n, timeout \\ @timeout) do
  5. rpc(%{command_name: "fib",
  6. args: n}, timeout)
  7. end
  8. end

Server:

  1. defmodule FibonacciServer do
  2. use AMQP.RPC.Server, [exchange: "",
  3. queue: "rpc_queue",
  4. commands: [:fib]]
  5. ## adapted from https://gist.github.com/stevedowney/2f910bd3d72678b4cf99
  6. def fib(0), do: 0
  7. def fib(n)
  8. when is_number(n) and n > 0,
  9. do: fib(n, 1, 0, 1)
  10. def fib(_), do: [error: "positive integers only"]
  11. def fib(n, m, _prev_fib, current_fib)
  12. when n == m,
  13. do: current_fib
  14. def fib(n, m, prev_fib, current_fib),
  15. do: fib(n, m+1, current_fib, prev_fib + current_fib)
  16. end

Installation

Available in Hex, the package can be installed as:

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

    1. def deps do
    2. [{:amqp_rpc, "~> 0.0.7"}]
    3. end
  2. Ensure amqp_rpc is started before your application:

    1. def application do
    2. [applications: [:amqp_rpc]]
    3. end