FerrymanEx
is a pure Elixir JSONRPC2 Client & Server realization.
Ferryman is a JSONRPC 2.0 Client & Server realization for Erlang and Ruby.
def deps do
[
{:ferryman_ex, github: "superlistapp/ferryman_ex"}
]
end
To get started, make sure you have a running instance of Redis.
FerrymanEx
uses Redix as redis driver.
You can start a local redis instance by running docker run --name my-redis -p 6379:6379 -d redis
First, let's define a JSONRPC2 handler, and define the functions we want to be handled by RPC calls.
defmodule ExampleHandler do
use JSONRPC2.Server.Handler
def handle_request("add", [x, y]) do
x + y
end
end
Now we can start our Ferryman Server.
iex> {:ok, pid} = Ferryman.Server.start_link(redis_config: [], channels: ["mychannel"], handler: ExampleHandler)
The default redis_config
will look for a redis instance on "localhost:6379"
.
For more configuration options, please check the Redix Docs.
You can define a list of channels
, and pass the handler
module.
To start communicating with the Ferryman server, let's first start our redis process:
iex> {:ok, redis} = Redix.start_link()
Now we can simply call the functions, the server has implemented:
iex> Ferryman.Client.call(redis, "mychannel", "add", [1, 2])
{:ok, 3}
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright (c) 2022 Superlist