Class: Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/manband/util.rb

Overview

Utility classes

Constant Summary collapse

@@connection =
nil
@@channel =
nil
@@exchange =
nil

Class Method Summary collapse

Class Method Details

.enqueue(dest, data = {}) ⇒ Object

Send a message in context args: dest name of destination queue msg message to send. Message is a hash with keys operation and msg.



24
25
26
27
28
29
30
31
# File 'lib/manband/util.rb', line 24

def self.enqueue(dest,data= {})
  Utils.setcontext()
  msg = data.to_json
  queue = @@channel.queue(dest, :auto_delete => false, :durable => true)
  queue.bind(@@exchange)
  #@@exchange.publish(msg, :routing_key => dest)
  @@channel.direct("").publish(msg, :routing_key => dest)
end

.publish(dest, data = {}) ⇒ Object

Creates a context and sends a message args: dest name of destination queue msg message to send. Message is a hash with keys operation and msg.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/manband/util.rb', line 37

def self.publish(dest,data= {})
msg = data.to_json
EventMachine.run do
  connection = AMQP.connect(FlowConfig.config())
  channel    = AMQP::Channel.new(connection)
  #exchange = channel.direct()   
  #queue = channel.queue(dest, :auto_delete => false, :durable => true)
  #queue.bind(exchange)
  #exchange.publish(msg, :routing_key => dest) do
  channel.direct("").publish(msg, :routing_key => dest) do
  connection.close { EventMachine.stop }
  end
end
end

.setcontextObject



12
13
14
15
16
17
18
# File 'lib/manband/util.rb', line 12

def self.setcontext()
  if(@@connection==nil)
    @@connection = AMQP.connect(FlowConfig.config())
    @@channel    = AMQP::Channel.new(@@connection)
    @@exchange = @@channel.direct()
  end
end