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
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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









