(go) Go language nsq source interpretation two nsqlookupd, NSQD and Nsqadmin

Source: Internet
Author: User

Transferred from: http://www.baiyuxiong.com/?p=886
-----------------------------------------------------------------------

Previous Go Language nsq Source Interpretation-Basic introduction introduced the most basic NSQ environment construction and use. In the last use, we used several commands: NSQLOOKUPD, NSQD, nsqadmin, curl, and Nsq_to_file, and saw several "Hello World" written with the Curl command saved in the hard drive file by the Nsq_to_file command. In this section, you will describe the roles and usages of these commands.

nsqlookupd:

Official document explanation see: http://bitly.github.io/nsq/components/nsqlookupd.html

In the official words is: NSQLOOKUPD management topology information, the client based on a specific topic query NSQLOOKUPD to find NSQD producers and NSQD broadcast topic and channel information. More difficult to understand, so next, with the popular words to explain.

First of all, talk about something else, the students who have used Linux may find that many applications under Linux, such as Apache, MySQL, FTP, and so on, their service names are at the end of D. Such as:

Apache-httpd

MySQL-mysqld

Vsftp-VSFTPD

The final end of D is the meaning of daemon, the daemon, which does not stop execution because the terminal window is closed. Apache, for example, executes service httpd start, Apache starts, and after the terminal shuts down, Apache still runs in the background.

Well, now you'll find that our nsqlookupd and NSQD also end in D, suggesting that they might be daemons, and indeed it is.

NSQLOOKUPD is a similar Apache-like background service, it can be understood as the nerve center of the whole NSQ system, after booting, it will listen to two ports at the same time, on 4160 ports, establish a TCP server for the data communication with NSQD. On 4161, an HTTP server is created for data interaction with nsqadmin.

Nsqd

Official Document Address: http://bitly.github.io/nsq/components/nsqd.html

The official explanation is: Nsqd receive, queue, send message to client.

In the previous lecture, the second command executed: nsqd–lookupd-tcp-address=127.0.0.1:4160

Represents the start of a NSQD service, and also tells the service that the NSQLOOKUPD address is in 127.0.0.1:4160. 4160 Port, which is the address of the TCP erver that nsqlookupd listens to. With this address, NSQD can establish a connection with NSQLOOKUPD and then interact with the data. At the same time, NSQD will listen to the 4151 port by default, receiving message data sent in HTTP mode.

Nsqadmin

Official documents See: Http://bitly.github.io/nsq/components/nsqadmin.html

Provides a browser-accessible Web page for real-time viewing of cluster status and performing some administrative operations.

In the previous lecture, the third command: nsqadmin–lookupd-http-address=127.0.0.1:4161

Indicates the start of nsqadmin, and also tells the service, NSQLOOKUPD listen to the HTTP address in 127.0.0.1:4161, so that Nsqadmin will also establish a connection with the NSQLOOKUPD, data interaction. The nsqadmin itself listens on port 4171, providing a Web service for the browser to access and view the data. So in the last lecture, we ended up viewing statistics by visiting http://127.0.0.1:4171/.

Curl

This should be familiar with the command, which can initiate a network request to the specified URL. You can refer to the URL:

Http://blog.51yip.com/linux/1049.html

In the previous lecture:

curl-d "Hello World 1″" Http://127.0.0.1:4151/put?topic=test "

Indicates the POST request to the URL http://127.0.0.1:4151/put?topic=test, the parameter is Hello World 1, this 4151 port, just nsqd listening port, that is, NSQD can interface network sent information, And put in the queue to save, for the message "consumer" to take out the data and processing. So the previous introduction to NSQD mentioned "Nsqd receive, queue, send message to client." ”。

Nsq_to_file

This is NSQ provides a simple message "consumer", he put a specified "topic" under the data exists in the specified file.

Last spoken command:

nsq_to_file–topic=test–output-dir=f:\tmp–lookupd-http-address=127.0.0.1:4161

Indicates that the data under the specified topic test is placed below the directory F:\tmp. So you can see that there are three Hello world saved in the file because we curl the topic=test url three times to Hello World.

At the same time you may notice that the last parameter specified by Nsq_to_file, lookupd-http-address 4161 Port is nsqlookupd address, not nsqd, and our curl message is sent to NSQD 4151 port, What is the reason for this?

I have not read the source code, hehe, so, the current speculation is because NSQLOOKUPD maintenance of all NSQD state. Once you know the address of nsqlookupd, you can ask NSQLOOKUPD for all the NSQD information.

Add a diagram:

(go) Go language nsq source interpretation two nsqlookupd, NSQD and Nsqadmin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.