Class: EstormMessageProcessor::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/estorm-message-processor/client.rb

Instance Method Summary collapse

Instance Method Details

#bunny_send(url, flag, queuename, cmdhash) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/estorm-message-processor/client.rb', line 20

def bunny_send(url,flag,queuename,cmdhash)
 @conn,@channel=setup_bunny(url,flag)
 @queue    = @channel.queue(queuename)
 #cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
 @channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => @queue.name)
 @conn.close  
end

#bunny_send_no_close(queuename, cmdhash) ⇒ Object

def bunny_send_no_close(url,flag,queuename,cmdhash)



31
32
33
34
35
36
# File 'lib/estorm-message-processor/client.rb', line 31

def bunny_send_no_close(queuename,cmdhash)
 # @conn,@channel=setup_bunny(url,flag)
 @queue    = @channel.queue(queuename)
 #cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
 @channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => @queue.name)
end

#connectionObject



27
28
29
# File 'lib/estorm-message-processor/client.rb', line 27

def connection
  @conn
end

#setup_bunny(url, flag) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/estorm-message-processor/client.rb', line 7

def setup_bunny(url,flag)
#maybe save this as global to speed it up.
begin
  @conn = Bunny.new(url) if flag
  @conn = Bunny.new if !flag
  @conn.start
rescue Bunny::PossibleAuthenticationFailureError => e
  puts "Could not authenticate as #{@conn.username}"
end
@channel   = @conn.create_channel
#puts "connected: #{conn.inspect}"
[@conn,@channel]
end