安裝
brew install nsq
啟動(dòng)
啟動(dòng)nsqlookupd
nsqlookupd
啟動(dòng)nsqd
nsqd --lookupd-tcp-address=127.0.0.1:4160
但是安裝官網(wǎng)上這樣操作在后面的步驟中遇到了問(wèn)題闻坚,具體的稍后再講。
后來(lái)我用的是:
nsqd --lookupd-tcp-address=127.0.0.1:4160 --broadcast-address=127.0.0.1
后面再講原因
啟動(dòng)nsqadmin
nsqadmin --lookupd-http-address=127.0.0.1:4161
啟動(dòng)之后就可以訪問(wèn)http://127.0.0.1:4171/
蚓峦,看到圖形化界面了
建立topic
curl 'http://127.0.0.1:4161/topic/create?topic=test' -d ''
建立channel
這里建立3個(gè)channel
curl 'http://127.0.0.1:4161/channel/create?topic=test&channel=ch1' -d ''
curl 'http://127.0.0.1:4161/channel/create?topic=test&channel=ch2' -d ''
curl 'http://127.0.0.1:4161/channel/create?topic=test&channel=ch3' -d ''
啟動(dòng)nsq_to_file接收指定的topic
nsq_to_file --topic=test --channel=ch1 --output-dir=/tmp/ch1 --lookupd-http-address=127.0.0.1:4161
nsq_to_file --topic=test --channel=ch2 --output-dir=/tmp/ch2 --lookupd-http-address=127.0.0.1:4161
nsq_to_file --topic=test --channel=ch3 --output-dir=/tmp/ch3 --lookupd-http-address=127.0.0.1:4161
到這里就報(bào)如下錯(cuò):
并且訪問(wèn)http://127.0.0.1:4171/時(shí)點(diǎn)擊topic也會(huì)報(bào)錯(cuò)。
看上面的報(bào)錯(cuò)信息跺涤,應(yīng)該就是連接不上nsqd.注意到nsqd的命令行參數(shù)草慧。
-broadcast-address string
address that will be registered with lookupd (defaults to the OS hostname) (default "PROSNAKES.local")
默認(rèn)是操作系統(tǒng)主機(jī)名,客戶端無(wú)法識(shí)別吸祟。
在Mac上應(yīng)該顯示指定
nsqd --lookupd-tcp-address=127.0.0.1:4160 --broadcast-address=127.0.0.1
這樣就可以連接成功了虏肾。
向指定topic發(fā)送消息
curl -d 'hello world 1' 'http://127.0.0.1:4151/pub?topic=test'