Class: AMQP::Hermes::Transmitter

Inherits:
Object
  • Object
show all
Includes:
Connectivity
Defined in:
lib/amqp-hermes/transmitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connectivity

#channel, #connection, #open?, #open_channel, #open_connection

Constructor Details

#initialize(queue = nil, topic = nil, options = {}) ⇒ Transmitter

Returns a new instance of Transmitter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/amqp-hermes/transmitter.rb', line 7

def initialize(queue=nil, topic=nil, options={})
  @queue = queue

  if topic.is_a?(Hash)
    options = topic.clone
    topic   = options[:topic]
  end

  options[:auto_delete] ||= true

  topic ||= "pub/sub"
  @exchange = channel.topic(topic, options)

  @transmitting = false
end

Instance Attribute Details

#queueObject (readonly)

Returns the value of attribute queue.



6
7
8
# File 'lib/amqp-hermes/transmitter.rb', line 6

def queue
  @queue
end

Instance Method Details

#closeObject



39
40
41
42
# File 'lib/amqp-hermes/transmitter.rb', line 39

def close
  AMQP::Hermes.wait_for(self, :done_transmitting?)
  super
end

#done_transmitting?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/amqp-hermes/transmitter.rb', line 35

def done_transmitting?
  @transmitting == true ? false : true
end

#transmit(payload, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/amqp-hermes/transmitter.rb', line 23

def transmit(payload, options={})
  @transmitting = true

  options.merge!(
    :routing_key => @queue
  ) unless options.has_key?(:routing_key)

  @exchange.publish( payload, options ) do
    @transmitting = false
  end
end