Class: Cpi::Connector

Inherits:
Object
  • Object
show all
Defined in:
lib/cpi/connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, logger) ⇒ Connector

Returns a new instance of Connector.



6
7
8
9
10
# File 'lib/cpi/connector.rb', line 6

def initialize params={}, logger
  @queue = params.delete(:queue)
  @params = params
  @logger = logger
end

Instance Method Details

#test_connectivityObject



24
25
26
27
28
29
30
# File 'lib/cpi/connector.rb', line 24

def test_connectivity
  @started = false
  start
  "Event Connector can connect to AMQP server at #{@params[:host]}:#{@params[:port]}"
rescue StandardError => e
  e.message
end

#transmit(message, options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cpi/connector.rb', line 12

def transmit(message, options = nil)
  options ||= {}
  options[:before_retry] = lambda { @started = false }

  with_retries options do
    start
    queue = options[:queue] || @queue
    @exchange.publish(message, :key => queue, :persistent => true)
    @bunny.tx_commit
  end
end