scherrey

scherrey

How to expose Erlang GenServices to Elixir/LiveView PubSub

We have a backend system developed in Erlang with a bunch of actors. We want to build a front-end system in Elixir/LiveView and hopefully avoid duplication of content/purpose. What’s most desirable is if we can expose some of the Erlang processes via the LiveView Pub/Sub capabilities. Is there some way we can add a behavior/interface to some of our Erlang GenServers so it will appear like any other event publisher to our Elixir LiveView app?

Most Liked

ruslandoga

ruslandoga

:wave: @scherrey

Is there some way we can add a behavior/interface to some of our Erlang GenServers so it will appear like any other event publisher to our Elixir LiveView app?

Provided they are in the same cluster, they can probably “just” publish messages in the format Phoenix PubSub expects to any pg group (group can be the PubSub adapter name (usually MyApp.PubSub.Adapter) thanks to backwards compitability) which Phoenix PubSub workers joined.

PhxPubSubWorkers = pg:get_members('Elixir.Phoenix.PubSub', _AdapterName = 'Elixir.MyApp.PubSub.Adapter'),
lists:foreach(fun(Pid) ->
    Pid ! {forward_to_local, Topic, Message, _Dispatcher = 'Elixir.Phoenix.PubSub'}
end, PhxPubSubWorkers).

For the Topic it would probably be easiest if the liveviews subscribe to some predefined one. If not, then it’s also possible to get the channels used by the liveview processes and broadcast to them directly.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
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
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement