オライリー の Golang 本で NSQ を知った。
この中で NSQ でメッセージングを行っていたのだが、いざ自分で使ってみて Consumer を複数起動したときに、Producer 1 に対して Consumer 1 しか通信していなかった。
そしてきれいにバランシングしていた。
これはそもそも NSQ の正常な動作っぽい。
Guillaume's Thoughts: First look at NSQ
要は、Topic と Channels は2つのモード、 broadcast
と balancing
で動作する。
Producer は Topic にしかひもづかない、
Consumer は Topic -> Channel にひもづく、
というのがまず基本。
その上で、Consumer でのチャンネル名の付け方で broadcast
と balancing
がわかれる。
Balancing
チャンネル名を同じにする
- Consumer1 subscribe to mytopic / mychannel
- Consumer2 subscribe to mytopic / mychannel
- Consumer3 subscribe to mytopic / mychannel
- Producer1 published to mytopic
Broadcast
チャンネル名を異なるものにする
- Consumer1 subscribe to mytopic / mychannel1
- Consumer2 subscribe to mytopic / mychannel2
- Consumer3 subscribe to mytopic / mychannel3
- Producer1 published to mytopic
これで Producer が Publish するとブロードキャストするのか、バランシングするのか挙動を柔軟にかえることが出来ます。
もちろん、 broadcast
と balancing
をまぜることも可能性です。
参考URL
Golang / go-nsqからnsqを利用してみる - Qiita
おわり。