sharkmyster

sharkmyster

Is it possible to share a Phoenix Pubsub with an external dependency?

Hi,

I’m building a little web app in phoenix. I want the app to allow users to play a dice game together. I have written all the game logic and genserver implementation in a separate application called DiceGame. This is included as a dependency in the phoenix app. The dice game app has an external api like"

DiceGame.new_game()
DiceGame.make_move(game_id, dice_guess)

So I have a Phoenix.Pubsub service running in the Phoenix app. When one player makes a move, how can the DiceGame make a Pubsub.broadcast using the Phoenix app’s pubsub service?

First Post!

igsp7

igsp7

By using the PubSub.PG2 adapter you can send messages across servers using distributed Elixir. You just need to connect the nodes. You can use the PG2 adapter by providing the adapter child spec option when you are starting the PubSub. For example if you start it with your application your start method in your application.ex file will look like this:

def start(_type, _args) do
    children = [
      {Phoenix.PubSub, name: MyApp.PubSub, adapter: Phoenix.PubSub.PG2},
    ]
    Supervisor.start_link(children, [])
end

Last Post!

Hermanverschooten

Hermanverschooten

I wrote about it last year, maybe it can help, Let's talk

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New

Other popular topics Top

baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement