Home

Awesome

Erlang NSQ client

This library implements a client to the NSQ Messaging Queue it does it's best to follow the guidelines provided by the project.

Missing features

OTP Compatibility

OTP 21.0 or above is required since 0.3.0, If you need a version of ensq which runs on an older OTP release, we suggest you use ensq 0.2.0.

Design

The Erlang process model fits the nsq client concept quite well so:

                                 topic*
                                 /     \
                                /       \
                               /         \
                              /           \
                      discovery_server     \
                           /    \           \
                          /      \          target*(PUB)
                         /        \
                        /          \
                      server      server2
                       / \          |
                      /   \         |
                     |     |        |
                 channel* channel* channel*


* - seperate process

API

Using ensq:init

One way to connect to nsq is using

Setting up topics separately

%% Setting up a topic separately.
DiscoveryServers = [{"localhost", 4161}], %% Discovery Server
Channels = [{<<"test">>,                  %% Channel name
			  ensq_debug_callback},       %% Callback Module
			  {<<"test2">>, ensq_debug_callback}],
ensq_topic:discover(
  test,                                   %% Topic
  DiscoveryServers,                       %% Discovery servers to use
  Channels,                               %% Channels to join.
  [{"localhost", 4150}]).                 %% Targets for SUBing


%% Sending a message to a topic
ensq:send(test, <<"hello there!">>).

Non registered channels

By default channels are registered processes that way it's possible to do things like ensq:send(test, ...) but for some situations registering the process and creating an atom for the name is not desirable to prevent poisoning the atom table. A dynamically created and destroyed channel would be an example of this. Passing a binary instead of a atom binary to ensq_topic:discover/4 will solve this issue but loose the advantage of being able to call the process by name, it still is possible to either save the PID on creation or retrieve it from ensq:list/1.

Configuration