0

I have two applications, both in Elixir, that need to communicate with each other:

  • 1 Server that has a PubSub with 2 topics, it broadcasts to one topic and listens to the other topic.

  • 1 Client, that should subscribe to the Servers PubSub topic and broadcast to the other topic.

The scenario I want to get is that I start the Server, and then start one or multiple Clients that can subscribe to the server.

It just needs to work locally in the terminal, so it doesn't need any fancy.

The Server uses :phoenix_pubsub, "~> 2.1" and the rest is mostly a Genserver for message-handling.

The client is basically just a Genserver that only needs to subscribe to the server and sends A message when it receives one.

Any tips how I can make them talk?

Elmseld
  • 83
  • 12
  • I would start by looking at this: https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html#module-adapters , for this to work, you will need to connect the nodes first. – Daniel Oct 20 '22 at 17:14
  • @Daniel yes i have read though the docs a couple of times but think it’s pretty slim on information, and I have hard time understanding how it is working. I understand that I need to connect the nodes I’m just very unsure how to do it. – Elmseld Oct 20 '22 at 17:29
  • this should cover everything you need to connect nodes: https://stackoverflow.com/a/17360786/8103819 – Daniel Oct 20 '22 at 17:36
  • @Elmseld while it may be useful to familiarize yourself with manually connecting nodes by hand, it'll be impractical to do so. You can also check [Peerage](https://hexdocs.pm/peerage/readme.html#usage) to streamline the node connecting part, even locally. It works out of the box with Phoenix.PubSub.G2. After you're able to connect the nodes, [broadcast!/4](https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html#broadcast!/4) will be able to send messages across connected nodes. – Raymond Lagonda Nov 06 '22 at 13:12

0 Answers0