1. Installation
Refer:
Http://nsq.io/deployment/installing.html
Http://www.baiyuxiong.com /? P = 873 (recommended .)
It is not recommended to directly drop the official binary releases version down and drop the bin directory.
We recommend that you use the "Building from source" method (refer to the following steps). In this way, you can lower the source to $ gopath/src and build the program into $ gopath/bin at the same time. (then add the bin directory to the environment variable $ sudo VI/etc/profile and add one row: Export Path = $ path: $ gopath/bin .)
Steps:
(Assuming a golang environment already exists)
1. vpnfq. (because you need to access code.google.com)
2. sudo chown-r xiaou $ gopath # This is set during golang environment. If it is not done, go get will report an error.
The following describes how to install nsq:
3. Go get github.com/kr/godep
4. Go get github.com/bmizerany/assert
5. godep get github.com/bitly/nsq /...
After execution, there will be many executable files in $ gopath/bin.
2. Deployment and Testing
Execute these commands on different terminals in sequence:
1. nsqlookupd
2. nsqd -- lookupd-TCP-address = 127.0.0.1: 4160
3. nsqadmin -- lookupd-http-address = 127.0.0.1: 4161
4. Curl-d "Hello World 1" "http: // 127.0.0.1: 4151/put? Topic = test"
5. nsq_to_file -- topic = test -- output-Dir = F: \ TMP -- lookupd-http-address = 127.0.0.1: 4161
6. Curl-d "Hello World 2" "http: // 127.0.0.1: 4151/put? Topic = test"
Curl-d "Hello World 3" "http: // FIG: 4151/put? Topic = test"
Browser access: http: // 127.0.0.1: 4171/
In this case, nsqlookupd is the hub. Nsqd is a service that accepts and forwards messages. Nsqadmin is redundant, a web page for viewing service status. Nsq_to_file is the consumer of the message. Curl-D sends a message to nsqd in http post mode, that is, the producer of the message. It can be seen that for the nsq message distribution system, only nsqlookupd + nsqd is required.
Illustration:
3. Python-written senders and consumers
This is the python library officially written by nsq. Here: https://github.com/bitly/pynsq
Installation:
PIP install pynsq
Test:
First, run the following command:
1. nsqlookupd
2. nsqd -- lookupd-TCP-address = 127.0.0.1: 4160
Then write The py script and run:
(Document: https://pynsq.readthedocs.org/en/latest/writer.html)
# Consumer:
Import nsq
Def handler (Message ):
Print message. Body
Return true
R = nsq. Reader (message_handler = handler,
Nsqd_tcp_addresses = ['127. 0.0.1: 100'],
Topic = 'test _ TOPIC ', channel = 'asdfxx', lookupd_poll_interval = 15)
Nsq. Run () # This run calls tornado. ioloop. ioloop. instance (). Start ()
# Producer:
Import nsq
Import tornado. ioloop
Import time
Def pub_message ():
Def finish_pub (Conn, data ):
Print data
Writer. Pub ('test _ TOPIC ', time. strftime (' % H: % m: % s'), finish_pub)
Writer = nsq. Writer (['127. 0.0.1: 100'])
Tornado. ioloop. periodiccallback (pub_message, 5000). Start ()
Nsq. Run ()
Preliminary Research on nsq