Duplicate channel messages created by model to endpoint broadcast

Hi,

I’m trying to run multiple servers each with their own phoenix instance. I’m trying to push messages to subscribers based on changes to the data model.

My problem is that using Model change to Endpoint.broadcast causes every server to emit the same message to connected clients.

Is there a standard way to distribute the messages such that only one is emitted?

Thanks,
Scott S.

My assumption had been that the user would seem to be connected to only one instance – but it seems to act like they’re connected to all of them…

They broadcast to a root PubSub, do all the phoenix servers have their own PubSub server running or are they all using the same one? I.E. in your config.exs file for each of your Phoenix server’s configurations, the pubsub key, what are all their values for each one? Are they all the same?

I think I understand now that the default lets you use Endpoint to distribute messages across all of your nodes (mine all use the same pubsub name/key.).

This is great for most of my messages, but for certain things, I need to push only states from the local node.

I found out that Phoenix.Pubsub has a direct_broadcast function that does just that – but it doesn’t seem to exist for channels (someone else pointed out that Absinthe wraps Pubsub and uses direct_broadcast for its local node models).

I could note the node name on join in socket assigns – then filter messages via handle_out – but it seems clunky. Is there any better way to get both types of local and global messaging working with Channels?

Thanks!
Scott S.

1 Like

I’ve never actually wanted purely local messaging (usually just use an ETS table or so if small process count) so I’m unsure… ^.^;

Anyone else know? The Absinthe people maybe?

Here’s where Absinthe uses it (though I’m an Elixir newbie and not sure I’m ready to extend or hack Phoenix.Pubsub quite yet).

1 Like