View Source Multiverses.PubSub (multiverses_pubsub v0.4.0)
Implements the Multiverses
pattern for Phoenix.PubSub
.
Messages topics are sharded by postfixing the topic with the universe id. Processes in any given universe are then only capable of subscribing to messages sent within the same universe.
don-t-use-this-in-prod
Don't use this in prodThis system should not be used in production to achieve sharding of communications channels.
phoenix-channels
Phoenix channelsThis does not currently support phoenix channels. PRs or test cases accepted.
recommended-setup
Recommended Setup
in-config-exs
in config.exs
config :my_app, Phoenix.PubSub, Phoenix.PubSub
in-test-exs
in test.exs
config :my_app, Phoenix.PubSub, Multiverse.PubSub
in-your-pubsub-using-modules
in your pubsub-using modules
defmodule MyPubSubModule do
@pubsub Application.compile_env!(:my_app, Phoenix.PubSub)
end
in-your-tests
in your tests
defmodule ModuleThatTestsPubSubTest do
use ExUnit.Case, async: true
setup do
Multiverses.shard(PubSub)
end
end
configuration
Configuration
Many PubSub applications will have subscriber processes that won't be attached to a test, but
still need to use the Multiverses.PubSub
interface for ad-hoc processes created. In this case,
provide the following line in your configuration:
Note that the default is to have strict: true
in-test-exs-1
in test.exs
config :multiverses_pubsub, strict: false
clustering
Clustering
Multiverses.PubSub
is tested to work in clustered elixir.
connecting-processes-to-shards-over-the-cluster
Connecting processes to shards over the clusterNote that if a process is running in a peer node, you should provide it with either:
- the universe id to link it
- a pid that has been sent over erlang distribution. If you provide a binary serialized pid (via
:erlang.term_to_binary/1
) the rehydrated pid will not be connected to the correct multiverse shard.
Link to this section Summary
Functions
See Phoenix.PubSub.dispatch/3
.
Link to this section Functions
broadcast_from(pubsub, from, topic, message, dispatcher \\ Phoenix.PubSub)
View Sourcebroadcast_from!(pubsub, from, topic, message, dispatcher \\ Phoenix.PubSub)
View Sourcedirect_broadcast(node_name, pubsub, topic, message, dispatcher \\ Phoenix.PubSub)
View Sourcedirect_broadcast!(node_name, pubsub, topic, message, dispatcher \\ Phoenix.PubSub)
View SourceSee Phoenix.PubSub.dispatch/3
.