Class: Skein::Client::Subscriber

Inherits:
Skein::Connected show all
Defined in:
lib/skein/client/subscriber.rb

Instance Attribute Summary

Attributes inherited from Skein::Connected

#channel, #connection, #context, #ident

Instance Method Summary collapse

Methods inherited from Skein::Connected

#close, #lock

Constructor Details

#initialize(exchange, routing_key = nil, connection: nil, context: nil) ⇒ Subscriber

Instance Methods =====================================================



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/skein/client/subscriber.rb', line 4

def initialize(exchange, routing_key = nil, connection: nil, context: nil)
  super(connection: connection, context: context)

  @exchange =
    case (exchange)
    when String, Symbol
      self.channel.topic(exchange)
    else
      exchange
    end

  @subscribe_queue = self.channel.queue('', exclusive: true)
  @subscribe_queue.bind(@exchange, routing_key: routing_key)
end

Instance Method Details

#listenObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/skein/client/subscriber.rb', line 19

def listen
  case (@subscribe_queue.class.to_s.split(/::/)[0])
  when 'Bunny'
    @subscribe_queue.subscribe(block: true) do |delivery_info, properties, payload|
      yield(JSON.load(payload), delivery_info, properties)
    end
  when 'MarchHare'
    @subscribe_queue.subscribe(block: true) do |, payload|
      yield(JSON.load(payload), )
    end
  end
end