Class: MicroBunny::Subscriber
- Inherits:
-
Object
- Object
- MicroBunny::Subscriber
- Defined in:
- lib/microbunny/subscriber.rb
Instance Method Summary collapse
-
#initialize(channel, exchange, callback) ⇒ Subscriber
constructor
A new instance of Subscriber.
- #records(records) ⇒ Object
- #topic(topic) ⇒ Object
Constructor Details
#initialize(channel, exchange, callback) ⇒ Subscriber
Returns a new instance of Subscriber.
3 4 5 6 7 8 |
# File 'lib/microbunny/subscriber.rb', line 3 def initialize(channel, exchange, callback) @channel = channel @exchange = exchange @callback = callback @settings = settings end |
Instance Method Details
#records(records) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/microbunny/subscriber.rb', line 16 def records(records) records.each do |record| queue = find_queue_for_record(record) queue.bind(exchange, routing_key: record.routing_key_matcher) queue.subscribe { |_info, , payload| callback.call(payload) } end end |
#topic(topic) ⇒ Object
10 11 12 13 14 |
# File 'lib/microbunny/subscriber.rb', line 10 def topic(topic) queue = find_queue(topic) queue.bind(exchange, routing_key: "*") queue.subscribe { |_info, , payload| callback.call(payload) } end |