下面的步驟將通過(guò)推送(publishing)、消費(fèi)(consuming)和歸檔(archiving)消息到本地磁盤(pán),在本地環(huán)境演示一個(gè)小型的 NSQ 集群
根據(jù)文檔安裝安裝 NSQ。
在另外一個(gè) shell 中,運(yùn)行 nsqlookupd:
$ nsqlookupd
再開(kāi)啟一個(gè) shell,運(yùn)行 nsqd:
$ nsqd --lookupd-tcp-address=127.0.0.1:4160
再開(kāi)啟第三個(gè) shell,運(yùn)行 nsqadmin:
$ nsqadmin --lookupd-http-address=127.0.0.1:4161
開(kāi)啟第四個(gè) shell,推送一條初始化數(shù)據(jù)(并且在集群中創(chuàng)建一個(gè) topic):
$ curl -d 'hello world 1' 'http://127.0.0.1:4151/put?topic=test'
最后,開(kāi)啟第五個(gè) shell, 運(yùn)行 nsq_to_file:
$ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161
推送更多地?cái)?shù)據(jù)到 nsqd:
$ curl -d 'hello world 2' 'http://127.0.0.1:4151/put?topic=test'
$ curl -d 'hello world 3' 'http://127.0.0.1:4151/put?topic=test'
http://127.0.0.1:4171/ 就能查看 nsqadmin 的 UI 界面和隊(duì)列統(tǒng)計(jì)數(shù)據(jù)。同時(shí),還可以在 /tmp 目錄下檢查 (test.*.log) 文件.這個(gè)教程中最重要的是:nsq_to_file (客戶端)沒(méi)有明確地指出 test 主題從哪里產(chǎn)生,它從 nsqlookupd 獲取信息,即使在消息推送之后才開(kāi)始連接 nsqd,消息也并沒(méi)有消失。