在测试NSQ的Quick Start发现这样一个问题,就是同时只能有一个订阅实例

$ nsq_to_file --topic=test --output-dir=/tmp --lookupd-http-address=127.0.0.1:4161 

当存在两个实例时则消息会被发送给其中的一个实例,而另一个则获取不到消息

在阅读到NSQ中NSQD的启动参数时,发现其支持在一个topic下建立多个channel,通过向topic发送消息,会向所有的channel发布。

测试

//创建topic
$ curl http://10.191.197.209:4151/create_topic?topic=public

//创建三个channel

$ curl http://10.191.197.209:4151/create_channel?topic=public\&channel=t1
$ curl http://10.191.197.209:4151/create_channel?topic=public\&channel=t2
$ curl http://10.191.197.209:4151/create_channel?topic=public\&channel=t3

//建立nsqdata t1 t2 t3四个文件夹分别存放nsqd数据及三个测试channel数据
mkdir nsqdata t1 t2 t3

//启动nsqd,nsqd可以独立启动,无需启动nsqlookupd
nsqd -data-path=/home/sunsl/nsqdata

//启动三个channel的接收端,这里使用nsq_to_file监听nsqd的tcp端口
nsq_to_file --topic=public --channel=t1 --output-dir=/home/sunsl/t1 --nsqd-tcp-address=127.0.0.1:4150
nsq_to_file --topic=public --channel=t2 --output-dir=/home/sunsl/t2 --nsqd-tcp-address=127.0.0.1:4150
nsq_to_file --topic=public --channel=t3 --output-dir=/home/sunsl/t3 --nsqd-tcp-address=127.0.0.1:4150

//向public发送测试数据
curl -d '向三个channel发送数据' 'http://10.191.197.209:4151/put?topic=public'
//cat t1,t2,t3文件夹下的log文件,数据显示正常获取

 

问题

  • 接收数据有延迟,原因未知,待查
posted on 2014-08-05 17:07  forrestsun  阅读(7180)  评论(1编辑  收藏  举报