Skip to content

Instantly share code, notes, and snippets.

@bschwartz
Created November 11, 2014 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bschwartz/55eb8c349fff0d87d95f to your computer and use it in GitHub Desktop.
Save bschwartz/55eb8c349fff0d87d95f to your computer and use it in GitHub Desktop.
Consume from multiple topics into a single queue
require 'nsq'
require 'thread'
queue = Queue.new
consumer_for_topic1 = Nsq::Consumer.new(
topic: 'topic1',
channel: 'multi-topic-consumer',
queue: queue
)
consumer_for_topic2 = Nsq::Consumer.new(
topic: 'topic1',
channel: 'multi-topic-consumer',
queue: queue
)
loop do
msg = queue.pop
puts msg.body
msg.finish
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment