This is a creation in Article, where the information may have evolved or changed.
Because the company needs to use the Message Queuing products in the business, I chose the NSQ product based on Golang Open source to record the pits in the deployments I encountered.
First install NSQ, this nothing to say, I was directly on the official website to download the bin file, directly deployed, the environment is CentOS 6.7, installed in the/opt/nsq-0.3.7.linux-amd64.go1.6 directory;
Next is installs the Nodejs, I installs is the v6.1.0 version, this step also has nothing good to say;
And then install NSQJS. This is a bit of a hole.
1, to see the version of the GCC;
$ gcc -v使用内建 specs。目标:x86_64-redhat-linux配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux线程模型:posixgcc 版本 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
2, because node. JS 4 Upgrades The V8 engine, requires that the GCC version is above 4.8, so update the GCC version first;
$ rpm -ivh https://www.softwarecollections.org/en/scls/rhscl/devtoolset-3/epel-6-x86_64/download/rhscl-devtoolset-3-epel-6-x86_64.noarch.rpm$ yum install devtoolset-3-gcc-c++临时使用最新版gcc:$ scl enable devtoolset-3 bash系统默认使用gcc-4.9$ echo "source /opt/rh/devtoolset-3/enable" >>/etc/profile
3, then install NSQJS, in order to reuse the project, I used the global installation, and then copy the NSQJS to the project node_modules can be;
$ npm install -g nsqjs
4, copy the NSQJS to the project's Node_modules directory;
5. Create a app.js file in the project, enter the following code and Save:
var nsq = require (' Nsqjs '); var reader = new nsq. Reader (' sys_topic ', ' Sys_chan ', {lookupdhttpaddresses: ' 127.0.0.1:4161 '}); Reader.connect (); Reader.on (' message ', Function (msg) {var t = new Date (); Console.log (' time [%s] Received message [%s]:%s ', T.format (' Yyyy-mm-dd hh:mm:ss '), Msg.id, msg.body.toString ()); Msg.finish ();});D Ate.prototype.Format = function (FMT) {//author:meizz var o = {"m+": This.getmonth () + 1,//month "d+": This.getdate (),//day "H +": this.gethours (),//Hour "m+": this.getminutes (),//Sub "s+": this.getseconds (),//sec "q+": Math.floor ((This.getmonth () + 3)/3),//Quarterly "S": this.getmilliseconds ()//msec}; if (/(y+)/.test (FMT)) FMT = Fmt.replace (regexp.$1, (this.getfullyear () + ""). substr (4-regexp.$1.length)); For (var k in O) if (New RegExp ("(" + K +) "). Test (FMT)) FMT = Fmt.replace (regexp.$1, (regexp.$1.length = = 1)? (O[k]): (("XX" + o[k]). substr (("" + O[k]).)); return FMT;}
6, in the Nsqadmin page, create topic for "Sys_topic" and channel for "Sys_chan";
7, in the application terminal, run this JS file
$ node app.js
8. Post a message in another terminal
$ curl -d '{"aa":"text","caption":"nsq_test","bool_v":true}' 'http://127.0.0.1:4151/put?topic=sys_topic&channel=sys_chan'
9, see we can very quickly receive the release of the message