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
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
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









