EasyRpc (EasyRpc v0.9.0)

Copy Markdown View Source

Main DSL module for EasyRpc.

Use this module to define RPC wrappers with the Spark DSL:

defmodule MyApp.RemoteApi do
  use EasyRpc

  config do
    # Option 1: Static node list
    nodes [:"api@node1", :"api@node2"]
    select_mode :round_robin
    module RemoteNode.Api
    timeout 5_000
  end

  rpc_functions do
    # Option 1: Using integer arity
    rpc_function :get_user, 1
    rpc_function :create_user, 2

    # Option 2: Using argument names (better IDE support)
    rpc_function :get_user, [:user_id]
    rpc_function :create_user, [:user_id, :name]
  end
end

Dynamic Node Discovery

You can also use dynamic node discovery via MFA (Module, Function, Args):

config do
  # Option 2: Dynamic node discovery
  nodes_provider {MyApp.Cluster, :get_backend_nodes, [:region]}
  module RemoteNode.Api
  timeout 5_000
end

The function must return a list of node names.

Options

  • :extensions (list of module that adopts Spark.Dsl.Extension) - A list of DSL extensions to add to the Spark.Dsl

  • :otp_app (atom/0) - The otp_app to use for any application configurable options

  • :fragments (list of module/0) - Fragments to include in the Spark.Dsl. See the fragments guide for more.

Summary

Functions

Returns the current version of EasyRpc.

Functions

version()

@spec version() :: String.t()

Returns the current version of EasyRpc.

Examples

iex> EasyRpc.version()
"0.9.0"