EasyRpc.RpcWrapper (EasyRpc v0.1.1)

View Source

This module provides a wrapper for RPC (Remote Procedure Call) functionalities. It includes functions to facilitate communication between different parts of the system or between different systems over a network.

Configuration for RpcWrapper

Put config to config.exs file, and use it in your module by using RpcWrapper. User need separate config for each wrapper, and put it in config.exs

:nodes List of nodes, or {module, function, args} to get nodes. :module Module of remote functions on remote node. :error_handling Enable error handling (catch all) or not. :select_node_mode Select node mode, support for random, round_robin, hash. :functions list of functions, each function is a tuple {function_name, arity} or {function_name, new_name, arity, opts}. :opts Map of options, including new_name, retry, error_handling. Ex: [new_name: :clear_data, retry: 3, error_handling: false]

config :app_name, :wrapper_name,
  nodes: [:"test1@test.local"],
  # or nodes: {MyModule, :get_nodes, []}
  error_handling: true, # enable error handling, global setting for all functions.
  select_node_mode: :random, # select node mode, global setting for all functions.
  module: TargetApp.RemoteModule,
  functions: [
    # {function_name, arity}
    {:get_data, 1},
    {:put_data, 1},
    # {function_name, arity, opts}
    {:clear, 2, [new_name: :clear_data, retry: 3, error_handling: false]},
  ]

usage: by using RpcWrapper in your module, you can call remote functions as local functions.

:otp_app, name of application will add config :config_name, name of config in application

defmodule DataHelper do
use EasyRpc.RpcWrapper,
  otp_app: :app_name,
  config_name: :account_wrapper

def process_remote() do
  case get_data("key") do
    {:ok, data} ->
      # do something with data
    {:error, reason} ->
      # handle error
  end
end

Summary

Functions

rpc wrapper, support for define macro.

rpc wrapper, support for define macro.

Functions

get_config!(app_name, config_name, atom)

rpc_call(arg, args)

rpc wrapper, support for define macro.

rpc_call_error_handling(arg, args)

rpc wrapper, support for define macro.