manhvu
Intro
EasyRpc for easy to wrap a remote function (rpc) to local module for convenience. Dev just to need add config for target nodes (or use {Module, :function, args} for get nodes in runtime) and add functions want to wrap then use EasyRpc with option for EasyRpc can read the config. Then call rpc in app like a local function.
This library help developer easy to wrap a remote procedure call (rpc, library uses Erlang
:erpcmodule).EasyRpc supports some basic features for wrapping rpc: retry, timeout, error_handling. Each function can has seperated options or use global options (config for all function in a module).
Source code is available on Github and package on Hex
Example
Add Configs
This way you can add config to config.exs/dev/prod.exs or runtime.exs(for runtime).
config :simple_example, :remote_defrpc,
nodes: [:"remote@127.0.0.1"], # or {ClusterHelper, :get_nodes, [:remote_api]},
select_mode: :round_robin
Declare functions
defmodule Remote
use EasyRpc.DefRpc,
otp_app: :simple_example,
config_name: :remote_defrpc,
# Remote module name
module: RemoteNode.Interface,
timeout: 1000
defrpc :get_data
defrpc :put_data, args: 1
defrpc :clear, args: 2, as: :clear_data, private: true, retry: 1
defrpc :put_data, args: [:name], new_name: :put_with_retry, retry: 3, timeout: 3000
end
Now call rpc like a local function
Remote.get_data()
Thanks for reading!
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
hauleth
Why I need to define remote functions as part of compile-time config instead of defining them, well, in module? With similar approach as I could do with
defdelegatefor example.manhvu
Simple & easy for newbies is thing for this libray and lib also help reduce boilerplate code & can use with our other module is ClusterHelper (like a global registry for cluster). Remember with with dynamic Elixir cluster much harder than static cluster.
Thanks for you comment!
hauleth
Yeah, but I find it easier to reason if instead of writing:
You would do:
D4no0
Totally agree with your version being more readable. I am in general not a fan of using the tuple format in code if it can be avoided, as it’s very hard to track down.
hauleth
In this case it also provides a way to write documentation for these generated functions, which is not possible with original approach.
manhvu
Yes, I think this way is better than config way. I will add support this in the next version. Thank you for your suggestion!
manhvu
I have added new way to wrapping rpc. More friendly than last one but still not good enough. I’ finding a way to improve defrpc macro. I hope I can back and improve this soon!
Add Configs
Declare functions
manhvu
After some updates, the library now has clearer docs and a better overall design.
It currently supports two ways to wrap RPC:
Note: This library works nicely with ClusterHelper, making it easier to build distributed systems in Elixir.