Class: Jackrabbit::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jackrabbit/client.rb

Constant Summary collapse

InvalidExchangeType =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Jackrabbit.config) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/jackrabbit/client.rb', line 8

def initialize(config = Jackrabbit.config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/jackrabbit/client.rb', line 5

def config
  @config
end

Instance Method Details

#bonded_queue(name, options = {}, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jackrabbit/client.rb', line 28

def bonded_queue(name, options = {}, &block)
  queue_opts, binding_opts, sub_options = split_options(options)

  queue = self.queue(name, queue_opts)
  receiver = MessageReceiver.new(channel, &block)

  queue.bind(exchange, binding_opts)

  queue.subscribe(sub_options) do |info, message, payload|
    receiver.handle(info, message, payload)
  end
end

#channelObject



12
13
14
# File 'lib/jackrabbit/client.rb', line 12

def channel
  @channel ||= connection.create_channel
end

#exchangeObject



16
17
18
19
20
21
22
# File 'lib/jackrabbit/client.rb', line 16

def exchange
  if %w(fanout direct topic).include?(config.exchange_type)
    @exchange ||= channel.send(config.exchange_type, config.exchange_name, config.exchange_options)
  else
    raise InvalidExchangeType, "The exchange type '#{config.exchange_type}' is invalid"
  end
end

#publish(message, options = {}) ⇒ Object



24
25
26
# File 'lib/jackrabbit/client.rb', line 24

def publish(message, options = {})
  exchange.publish(message, options)
end

#queue(name, options) ⇒ Object



41
42
43
# File 'lib/jackrabbit/client.rb', line 41

def queue(name, options)
  channel.queue(name, options)
end