AvroRPC
is an Elixir library for making RPC calls using the Avro protocol specification. Currently, AvroRPC
wraps functionality from both the eavro and ex_avro libraries and provides a unified client implementation for managing connections and calling methods across multiple AvroRPC
services.
If available in Hex, the package can be installed
by adding both avro_rpc
and eavro
to your list of dependencies in mix.exs
:
def deps do
[
{:avro_rpc, "~> 0.1.0"},
{:eavro, git: "https://github.com/sifoxdevteam/eavro.git", tag: "v0.0.3"}
]
end
You will also need to ensure that avro_rpc
is started before your application:
def application do
[
applications: [
:avro_rpc
]
]
end
AvroRPC
currently only provides an implementation for consuming AvroRPC endpoints as a client. When your application starts, AvroRPC
will attempt to connect to each service specified in your application's configuration.
You can configure AvroRPC
in your mix.exs
file, like so:
config :avro_rpc,
services: [
%{
name: :service_1,
hostname: "localhost",
port: 9015,
protocol: "./test/data/avro.json"
},
%{
name: :service_2,
hostname: "localhost",
port: 9000,
protocol: "./test/data/customer_profile.json"
}
]
AvroRPC
will open a connection for each item in the services
list of your config.
Each individual element in the services
list must be a Map
containing the following fields:
- name (
atom
): The name of the service you're connecting to - hostname (string): The hostname of the AvroRPC endpoint
- port (number): The port on which the AvroRPC endpoint receives TCP connections.
- protocol (string): The path to the Avro protocol definition file for the specific service.
AvroRPC
currently only exposes one public function: AvroRPC.Client.call/3
, which is used to call a method on a specific service, and pass in a list of arguments to that method.
For example, if you have a service named :test_server
, with a hello
method, you'd call it like so:
{:ok, response} = AvroRPC.Client.call(:test_server, :hello, ["world"])
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/avro_rpc.