Phoenix.PubSub.Local

Phoenix.PubSub.Local

PubSub implementation for handling local-node process groups.

This module is used by Phoenix pubsub adapters to handle their local node subscriptions and it is usually not accessed directly. See Phoenix.PubSub.PG2 for an example integration.

Summary

Functions

broadcast(fastlane, pubsub_server, pool_size, from, topic, msg)

Sends a message to all subscribers of a topic

start_link(server_name, gc_name)

Starts the server

subscribe(pubsub_server, pool_size, pid, topic, opts \\ [])

Subscribes the pid to the topic

subscribers(pubsub_server, topic, shard)

Returns a set of subscribers pids for the given topic

subscribers_with_fastlanes(pubsub_server, topic, shard)

Returns a set of subscribers pids for the given topic with fastlane tuples. See subscribers/1 for more information

unsubscribe(pubsub_server, pool_size, pid, topic)

Unsubscribes the pid from the topic

Functions

broadcast(fastlane, pubsub_server, pool_size, from, topic, msg)

Sends a message to all subscribers of a topic.

  • pubsub_server - The registered server name
  • pool_size - The size of the pool
  • topic - The string topic, for example "users:123"

Examples

iex> broadcast(MyApp.PubSub, 1, self, "foo")
:ok
iex> broadcast(MyApp.PubSub, 1, :none, "bar")
:ok

start_link(server_name, gc_name)

Starts the server.

  • server_name - The name to register the server under

subscribe(pubsub_server, pool_size, pid, topic, opts \\ [])

Subscribes the pid to the topic.

  • pubsub_server - The registered server name
  • pool_size - The size of the pool
  • pid - The subscriber pid
  • topic - The string topic, for example "users:123"
  • opts - The optional list of options. Supported options only include :link to link the subscriber to local

Examples

iex> subscribe(MyApp.PubSub, 1, self, "foo")
:ok

subscribers(pubsub_server, topic, shard)

Returns a set of subscribers pids for the given topic.

  • pubsub_server - The registered server name or pid
  • topic - The string topic, for example "users:123"
  • shard - The shard, for example 1

Examples

iex> subscribers(:pubsub_server, "foo", 1)
[#PID<0.48.0>, #PID<0.49.0>]

subscribers_with_fastlanes(pubsub_server, topic, shard)

Returns a set of subscribers pids for the given topic with fastlane tuples. See subscribers/1 for more information.

unsubscribe(pubsub_server, pool_size, pid, topic)

Unsubscribes the pid from the topic.

  • pubsub_server - The registered server name
  • pool_size - The size of the pool
  • pid - The subscriber pid
  • topic - The string topic, for example "users:123"

Examples

iex> unsubscribe(MyApp.PubSub, 1, self, "foo")
:ok

© 2014 Chris McCord
Licensed under the MIT License.
https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.Local.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部