Skip to content

xflagstudio/phoenix_pubsub_nats

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Phoenix Pubsub - Nats Adapter

NATS adapter for the Phoenix framework PubSub layer.

Usage

Add phoenix_pubsub_nats as a dependency in your mix.exs file.

def deps do
  [{:phoenix_pubsub_nats, git: "https://github.com/mtokioka/phoenix_pubsub_nats.git"}]
end

You should also update your application list to include :phoenix_pubsub_nats:

def application do
  [applications: [:phoenix_pubsub_nats]]
end

Edit your Phoenix application Endpoint configuration:

  config :my_app, MyApp.Endpoint,
    ...
    pubsub: [name: MyApp.PubSub,
             adapter: Phoenix.PubSub.Nats,
             options: [hosts: ["localhost"]]

The following options are supported:

  * `hosts` - The hostnames of the broker(defaults to [\"localhost:4222\"]);
  * `sub_pool_size` - Number of active connections to the broker for subscriber(defaults to 5);
  * `pub_pool_size` - Number of active connections to the broker for publisher(defaults to 5);

Notes

  def handle_out(type, payload, socket) do
    push socket, type, payload
    {:noreply, socket}
  end