View Source Multiverses.PubSub (multiverses_pubsub v0.5.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 prod

This system should not be used in production to achieve sharding of communications channels.

phoenix-channels

Phoenix channels

This does not currently support phoenix channels. PRs or test cases accepted.

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 cluster

Note 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

Link to this section Functions

Link to this function

broadcast(pubsub, topic, message, dispatcher \\ Phoenix.PubSub)

View Source
Link to this function

broadcast!(pubsub, topic, message, dispatcher \\ Phoenix.PubSub)

View Source
Link to this function

broadcast_from(pubsub, from, topic, message, dispatcher \\ Phoenix.PubSub)

View Source
Link to this function

broadcast_from!(pubsub, from, topic, message, dispatcher \\ Phoenix.PubSub)

View Source

See Phoenix.PubSub.child_spec/1.

Link to this function

direct_broadcast(node_name, pubsub, topic, message, dispatcher \\ Phoenix.PubSub)

View Source
Link to this function

direct_broadcast!(node_name, pubsub, topic, message, dispatcher \\ Phoenix.PubSub)

View Source

See Phoenix.PubSub.dispatch/3.

Link to this function

local_broadcast(pubsub, topic, message, dispatcher \\ Phoenix.PubSub)

View Source
Link to this function

local_broadcast_from(pubsub, from, topic, message, dispatcher \\ Phoenix.PubSub)

View Source

See Phoenix.PubSub.node_name/1.

Link to this function

subscribe(pubsub, topic, opts \\ [])

View Source
Link to this function

unsubscribe(pubsub, topic)

View Source