View Source PhoenixPubSubBuffered (PhoenixPubSubBuffered v0.1.0)

Phoenix PubSub adapter using :pg with at-least-once delivery.

To start it, list it in your supervision tree as:

{Phoenix.PubSub, name: MyApp.PubSub, adapter: PhoenixPubSubBuffered}

You will also need to add :phoenix_pubsub_buffered to your deps:

defp deps do
  [{:phoenix_pubsub_buffered, "~> 0.1.0"}]
end

Options

  • :name - The required name to register the PubSub processes, ie: MyApp.PubSub
  • :pool_size - The number of producers and workers to run on each node, allowing concurrent message delivery.
  • :buffer_size - The amount of messages to maintain in memory

Implementation

The in memory buffer is a ring buffer, meaning that a constant number of messages are maintained and once the buffer is full, new messages overwrite the oldest message in the buffer.

This means that if a node in the cluster is disconnected long enough that when it reconnects, its cursor points to a message that no longer exists, it will receive a special message over pubsub: {:cursor_expired, node@host}

Applications are encouraged to handle and act on this message to get to a valid state, such as reloading all state from a source of truth like the db or another node. While this technically means that we don't guarentee every node will receive every message, we can guerentee that there are no gaps in messages. Recipt of message 3 guarentees you've received messages 1 and 2.

Summary

Functions

Returns a specification to start this module under a supervisor.

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.