Message queues provide a new asynchronous way for services to communicate with each other. Compared to an API, a message queue has many advantages, such as :

  • Optimize performance
  • The Producer doesn’t need to wait for the Consumer to finish their jobs thus optimizing the performance
  • Reliability
  • The level of persistence in messaging queue helps to minimalize the data loss when part of the system goes down
  • Scalability
  • Scaling the producer and consumer separately to meets your needs

1. Introduction to NSQ

Image for post

NSQ is an open source realtime distributed messaging platform which is a successor from simplequeue.

The core component of the NSQ is consist of :

  • 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 broadcast topics and channel information.
  • nsqadmin is a Web UI to view aggregated cluster stats in realtime and perform various administrative tasks.

A single nsqd instance is designed to handle multiple streams of data at once. Streams are called “topics” and a topic has 1 or more “channels”. Each channel receives a copy of all the messages for a topic.

Both topics and channels are not pre-configured. Topics are created on first publish on the named topic or by subscribing channel on the named topic. Channels are created on the first use of subscribing to the named channel.

and both buffer data independently of each other.

nnel generally does have multiple clients connected and each message will be delivered to a random client

#nsq #golang #docker #go

Implementing Messaging Queue NSQ in Golang using Docker
19.40 GEEK