Real-time Distributed Messaging On FreeBSD With NSQ

freebsd nsq distributed

How To Install NSQ?

Install NSQ by port mechanism:
# cd /usr/ports/net/nsq
# make install clean
Install NSQ by package manager:
# pkg install nsq

Create Local NSQ Cluster

The following commands run a small NSQ cluster on your local machine and send messages and archiving messages to disk.
issue nsqlookupd:
# nsqlookupd
in another shell, start nsqd:
# nsqd –lookupd-tcp-address=127.0.0.1:4160
in another shell, start nsqadmin:
# nsqadmin –lookupd-http-address=127.0.0.1:4161
publish an initial message (creates the topic in the cluster, too):
# curl -d ‘BSDMAG MSG 1’ ‘http://127.0.0.1:4151/pub?topic=bsdmag’

when you send a message to a topic for the first time, a topic will be created.
-d (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way, that a browser does when a user has filled in an HTML form and presses the submit button.
finally, in another shell, start nsq_to_file:
# nsq_to_file –topic= bsdmag –output-dir=/tmp –lookupd-http-address=127.0.0.1:4161
nsq_to_file acts as a client and copy messages from memory to disk.
publish more messages to nsqd:
# curl -d ‘BSDMAG MSG 2’ ‘http://127.0.0.1:4151/pub?topic=bsdmag’
# curl -d ‘BSDMAG MSG 3’ ‘http://127.0.0.1:4151/pub?topic=bsdmag’
to verify things worked as expected, in a web browser open http://127.0.0.1:4171/ to view the nsqadmin UI and see statistics. Also, check the contents of the log files (test.*.log) written to /tmp.
The important lesson here is that nsq_to_file (the client) is not explicitly told where the test topic is produced, it retrieves this information from nsqlookupd and, despite the timing of the connection, no messages are lost.

You can get full edition at:
http://contents.meetbsd.ir/ebook/nsq_bsdmag.pdf
Or:
https://bsdmag.org/download/real-time-distributed-messaging-freebsd-nsq/


enter image description here