如何只订阅 nsq 某个 topic下的特定channel?

本地环境:
testtopic下 有 两个channel: testchannel1, testchannel2,通过nsq_to_http的方式把数据消费到http接口上
e.g:
消费者1:
/usr/local/opt/nsq/bin/nsq_to_http --topic=testtopic --channel=testchannel1 --lookupd-http-address=127.0.0.1:4161 --post=http://xx.xx.xx/index.php?typ... --content-type=application/x-www-form-urlencoded
消费者2:
/usr/local/opt/nsq/bin/nsq_to_http --topic=testtopic --channel=testchannel2 --lookupd-http-address=127.0.0.1:4161 --post=http://xx.xx.xx/index.php?typ... --content-type=application/x-www-form-urlencoded

测试执行:
curl -d "hello=world&a=1" 'http://127.0.0.1:4151/pub topic=testtopic&channel=testchannel1'

结果:
http://xx.xx.xx/index.php 中 可以接收到 type=consumer2 的请求

问题:
我不管往哪个channel下push数据, 我的两个消费者都会同事接收到数据。 那我的业务逻辑就乱套了。我不明白nsq 多个channel 到底是怎么用的? 我知道应该是我使用的问题,所以请各位指导一下 如何 只消费特定 channel下的数据?

阅读 4.6k
1 个回答

思维走入误区

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进