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?
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.
Thanks so much for the pointers. Looks like something worth trying out.
– Ben Scherrey