A clustering strategy for libcluster using PostgreSQL LISTEN/NOTIFY and Postgrex.Notifications.
Many Elixir applications already depend on a single PostgreSQL database. That same database is used to communicate between nodes and form a cluster without any additional infrastructure.
This package can be installed from hex by adding libcluster_postgrex_notifications to your list of dependencies in mix.exs:
def deps do
[
{:libcluster_postgrex_notifications, "~> MAJ.MIN"}
]
endYou can determine the latest version by running mix hex.info libcluster_postgrex_notifications in
your shell, or by going to the libcluster_postgrex_notifications page on Hex.pm.
Add the strategy and config to your topologies.
config :libcluster,
topologies: [
postgrex_notifications_example: [
strategy: Cluster.Strategy.PostgrexNotifications,
config: [
postgrex: MyApp.Postgrex,
notifications: MyApp.Notifications,
channel: "libcluster_postgrex_notifications"
]
]
]Make sure postgrex and notifications correspond to pids or process names of Postgrex and Postgrex.Notifications.
# Starting these under a Supervisor is a better idea
{:ok, _} = Postgrex.start_link(opts, name: MyApp.Postgrex)
{:ok, _} = Postgrex.Notifications.start_link(opts, name: MyApp.Notifications)