NSQ is a real-time distributed messaging platform written in Go and created by well known service bit.ly.
It is simple and easy to use and has a good GUI of admin. NSQ is one of the best option if you want to implement Message Queue.
Concept of Message Queue
Message Queue is an implementation of the publisher/subscriber architectural pattern which is used for communication between different parts (applications, services, etc) of your system.
In short, when an event happens by a message published (producer) to the Queue (shown as picture above). Any services that interested in that services will subscribe (consumer) to get the message from the Queue.
NSQ Component
NSQ components consist of nsqd, nsqlookupd, nsqadmin.
nsqd is the daemon that receives, queues, and delivers messages to clients.
nsqlookupd is the daemon that manages topology information. Clients query nsqlookupd
to discover
nsqd
producers for a specific topic and nsqd
nodes broadcasts topic and channel information
nsqadmin is a Web UI to view aggregated cluster stats in realtime and perform various administrative tasks.
nsqadmin GUI
Download
First of all, you need to download the binary here as following your operating system and in my case, I use Windows then I download binary for Windows.
Open extracted folder and there you can see different executables:
- nsqlookupd.exe
- nsqd.exe
- nsqadmin.exe
- .. and many others
Step 1. Run nsqlookupd
Open extracted directory in shell/command terminal you prefer and run
C:\nsq-1.2.1.windows-amd64.go1.16.6\bin>nsqlookupd.exe
You should see the following output as below
one is using TCP with port 4160 and another is using HTTP with port 4161
Step 2. Run nsqd
Next step, run nsqd in terminal
Step 3. Publish a Message
If the request is 200 OK, our new topic will be created automatically
Step 4. Run nsqadmin
Step 5. Alternative to check with nsq_to_file
Open in terminal to execute nsq_to_file
C:\nsq-1.2.1.windows-amd64.go1.16.6\bin>nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
{"Hello World 2"}
{"Hello World 3"}