Class: Bunnicula::Relay

Inherits:
Object show all
Extended by:
DslBase
Defined in:
lib/bunnicula/relay.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DslBase

dsl_attr

Instance Attribute Details

#source_exchangeObject (readonly)

Returns the value of attribute source_exchange.



5
6
7
# File 'lib/bunnicula/relay.rb', line 5

def source_exchange
  @source_exchange
end

#target_exchangeObject (readonly)

Returns the value of attribute target_exchange.



5
6
7
# File 'lib/bunnicula/relay.rb', line 5

def target_exchange
  @target_exchange
end

Instance Method Details

#from(*args) ⇒ Object



7
8
9
10
11
12
# File 'lib/bunnicula/relay.rb', line 7

def from(*args)
  return @source_exchange if args.length == 0
  options = args.extract_options!
  exchange_name = args.pop
  @source_exchange = Bunnicula::Exchange.new(exchange_name,options)
end

#queue_nameObject

Operational



22
23
24
# File 'lib/bunnicula/relay.rb', line 22

def queue_name
  "bunnicula.#{from.name}"
end

#start(amq, bunny) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bunnicula/relay.rb', line 26

def start(amq,bunny)
  DaemonKit.logger.info "Starting relay from:#{from.name} to:#{to.name || from.name}"
  @channel = amq
  @bunny = bunny

  prepare_destination_exchange
  bind_to_source_exchange
  subscribe_to_queue

  DaemonKit.logger.info "Relay started"

end

#to(*args) ⇒ Object



14
15
16
17
18
19
# File 'lib/bunnicula/relay.rb', line 14

def to(*args)
  return @target_exchange || @source_exchange if args.length == 0
  options = args.extract_options!
  exchange_name = args.pop
  @target_exchange = Bunnicula::Exchange.new(exchange_name,options)
end