gus

gus

Calling a GenServer on a remote machine

Hey all, happy 2024!

I think I have on my hands a configuration and OTP problem - I’m pretty sure I have all the pieces, just not sure how to put it together.

I have a Nerves device which is connected to a sensor. I have created a GenServer to read the sensor periodically, save the data and provide it upon a caller’s request. This device also a has a LiveView UI which graphs the value of the sensor over time. This all works great on the device.

Where it breaks down is in development - I want to be able to develop the UI on my local machine, but use live data by calling the GenServer running on the device. I have enabled epmd and can connect to the remote node through iex, but now I’m trying to figure out how to ‘re-route’ all of the calls to the sensor GenServer to the Nerves device when running the application on the host.

I am considering two approaches to this problem. First, GenServer will accept any name registration as outlined in the docs, including processes on remote nodes. I think I could look up the remote PID on application start, and store that in application config for use later. As a second approach, I think there should be a way to use Registry or :global to lookup the correct process to direct the requests to.

Are there any recommendations on how to best do this?

Thanks!

Most Liked

hubertlepicki

hubertlepicki

No, and it’d be interesting to see what works and what doesn’t work.

I am mentioning it because I saw the erlang/elixir code explicitly handling endiness in some blog posts about handling data from smart sensors, and I suspect that the distribution protocol will handle it just fine but the payloads you send between nodes may require conversion. For example: Smart Sensors with Erlang and AtomVM: Smart cities, smart houses and manufacturing monitoring - Erlang Solutions

mudasobwa

mudasobwa

Creator of Cure

Well, there are a lot of good libraries above, but as I see the problem statement, one does not need any external library, nor even pg here.

Just name a process as {:global, Name}, and make sure the nodes are connected (by calling Node.connect/1 and checking it with Node.list/0.

Then :global.whereis_name/1 will give you a remote PID back, and you might use all the functions from GenServer using {:global, Name} as a remote process name.

D4no0

D4no0

Well that is another question.

I am not entirely sure, but my thinking is that inter-node communication is using functionality from term_to_binary, there seems to be a more comprehensive documentation here: Erlang -- External Term Format

schneebyte

schneebyte

Erlang -- pg is simple, flexible and already included in Erlang.

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

yurko
Here are few pieces of (common) Linux knowledge that we use for reasonably small one server apps. We use Ubuntu but this should work for ...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement