Skip to content
Idiomatic Elixir client for messaging system
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Initial Commit. Implement pubsub and nats protocol Jul 22, 2016
.travis.yml Add OTP 21 to .travis.yml for CI Jul 10, 2018

NatsEx Build Status

An idiomatic Elixir client for messaging system

Currently PubSub functionality is implemented.

Getting started

You can start a connection with Natsd like this. See NatsEx.Connection for configuration options.

{:ok, conn} = NatsEx.Connection.connection


For subscription to a certain topic, you can use sub/2 or sub/3 in NatsEx.Connection module. You can also give a queue group for the subscription.

:ok = NatsEx.Connection.sub(conn, "") # No queue group
:ok = NatsEx.Connection.sub(conn, "", 22) # Queue group 22

When a new message comes to a certain topic, a new message is received by all the subscribers. The message format is {:nats_ex, :msg, subject, reply_to_subject, payload}

When the connection is down(closed by the server), all the subscribers receive a message {:nats_ex, :conn_down}


For publishing to a certain topic, you can use pub/3 or pub/4 in NatsEx.Connection module. reply_to topic is optional.

:ok =, "", "This is a payload", "REPLY_SUBJECT")


You can unsubscribe to a certain topic by using unsub/2 or unsub/3 in NatsEx.Connection module. You can also specify the number of messages, after which the subscriber will be automatically subscribed.

:ok = NatsEx.Connection.unsub(conn, "", 10) # 10 is number of messages until unsubscription. This is optional


nats_ex is available on Hex. For installing, you can do this:

  1. Add nats_ex to your list of dependencies in mix.exs:
def deps do
  [{:nats_ex, "~> 0.1"}]
  1. Ensure nats_ex is started before your application:
def application do
  [applications: [:nats_ex]]


  • Authorization
  • TLS
  • Publish, Subscribe
  • Request, Reply


MIT License. Please see for more details.

You can’t perform that action at this time.