selfhost.directory

The index of self-hostable projects — ranked, categorized and served with live updates.
Own your data and stop giving it to big tech.

nsq logo

Self-host nsq

v1.3.0

Realtime distributed messaging and work queue platform

ReleaseOpen SourceMIT
docker run --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd
Updatedlast year
LanguageGo
Setup difficultyModerate
Stars
25 776
Ports
4150 (nsqd TCP interface for producer/consumer clients), 4151 (nsqd HTTP API (publish, stats, admin)), 4152 (nsqd HTTPS API), 4160 (nsqlookupd TCP interface used by nsqd broadcasts), 4161 (nsqlookupd HTTP discovery and admin interface), 4171 (nsqadmin web UI)
Docker
nsqio/nsq
nsqadmin web UI with aggregated cluster statistics and admin actions

What is nsq?

Should you self-host nsq?

nsq scores 70/100 on selfhost.directory (how scoring works) and ranks #5 of 12 in Message Broker. It has 25 776 GitHub stars, +7 in the last 30 days.

There was no stable release in the past 12 months, so check the repository's recent activity before you rely on it.

Setup is moderate: expect some configuration beyond a single command. An official Docker image is available. It is MIT-licensed and written mostly in Go.

Its closest alternative on selfhost.directory is Apache Kafka (82/100, 34 195 stars). It scores higher overall, so compare the two before you pick. See nsq vs Apache Kafka side by side.

Features

  • Admin web UI
  • Bundled CLI utilities
  • Client compression negotiation
  • Data format agnostic
  • Deferred message delivery
  • Disk-backed queue overflowMessages are not durable by default.
  • Distributed topology with no SPOF
  • External authorization serverAvailable in nsqd v0.2.29+
  • Horizontal scaling without brokers
  • HTTP publish and admin API
  • Load-balanced and multicast routing
  • Low-latency push delivery
  • Pub-sub with per-consumer channels
  • Runtime consumer discovery (nsqlookupd)
  • TLS transport security

nsq README

How to install nsq

Install nsq with Docker

docker pull nsqio/nsq
docker run --name lookupd -p 4160:4160 -p 4161:4161 nsqio/nsq /nsqlookupd
docker pull nsqio/nsq
docker run --name nsqd -p 4150:4150 -p 4151:4151 \
    nsqio/nsq /nsqd \
    --broadcast-address=<host> \
    --lookupd-tcp-address=<host>:<port>

One image contains every binary; pass the binary as the command, e.g. docker run nsqio/nsq /nsq_to_file. Mount the /data volume and set --data-path=/data to persist nsqd data.

How to configure nsq

  • -configpath to config file (all nsqd/nsqlookupd/nsqadmin binaries)
  • -tcp-addressnsqd 0.0.0.0:4150, nsqlookupd 0.0.0.0:4160nsqd/nsqlookupd: <addr>:<port> to listen on for TCP clients
  • -http-addressnsqd 0.0.0.0:4151, nsqlookupd 0.0.0.0:4161, nsqadmin 0.0.0.0:4171<addr>:<port> to listen on for HTTP clients (nsqd, nsqlookupd, nsqadmin)
  • -https-address0.0.0.0:4152nsqd: <addr>:<port> to listen on for HTTPS clients
  • -lookupd-tcp-addressnsqd: lookupd TCP address (may be given multiple times)

nsq releases & version history

@ Every self-hosted release, weekly

One Monday email with the week's stable releases across the directory.

FAQ

When would I want to use Writer then?

Use Writer when performance matters, because its TCP PUB and MPUB commands have less overhead than the HTTP equivalents.

Is the Tornado IOLoop required to publish?

No, the nsqd HTTP endpoints /pub and /mpub work from any language, and /mpub batches publishes atomically.

Why are you forcing me to use Tornado?

pynsq started as a consumer-focused library and NSQ's push-oriented protocol is simpler to consume in Python with an asynchronous framework.

Can NSQ do RPC?

It is possible but NSQ was not designed for that use case.

How are new topics announced to the cluster?

The first PUB or SUB creates the topic on an nsqd, its metadata propagates to the configured nsqlookupd, and readers discover it by polling lookupd.

Are there any limitations to the number of topics and channels a single nsqd can support?

There are no built-in limits; only the memory and CPU of the host running nsqd constrain it.

How do you recommend naming topics and channels?

Name a topic after the data in the stream and a channel after the work its consumers do, for example topic encodes and channel archive.

How can I mitigate deleting-topic failures during publish?

Deleting topics is infrequent; orchestrate timing so publishes that would recreate a topic wait until enough time has passed since the deletion.

When can a PUB or MPUB fail?

When the topic name breaks the naming spec, the message is too large, the topic is being deleted, nsqd is exiting cleanly, or the client connection fails.

Why force a client to handle responses to the TCP protocol's PUB and MPUB commands?

The protocol was kept simple and consistent so that safe behaviour is the default mode of operation.

Do I need a client library to publish messages?

No, you can publish through the HTTP /pub and /mpub endpoints, and most deployments do exactly that.

How many nsqlookupd should I run?

Only a few; 3 or 5 works well up to several hundred hosts and thousands of consumers, since lookupd nodes answer queries without coordinating and metadata is eventually consistent.

I just want to use nsqd as a work queue on a single node, is that a suitable use case?

Yes, nsqd runs standalone fine; nsqlookupd is only useful in larger distributed environments.

Why can't nsqlookupd be used by producers to find where to publish to?

NSQ only solves consumer-side discovery; the topic does not exist before the first publish, so producers publish to a local nsqd instead.

What is the recommended topology for nsqd?

Run an nsqd next to every service that produces messages; nsqd is lightweight with a bounded memory footprint, so it co-exists well and forms an independent sharded silo of data per host.

More in Message Broker

Rate this project

Click to rate — no account needed.

0 comments

Posting as guest
Loading comments…