Module: CPEE::Message

Defined in:
lib/cpee/message.rb

Constant Summary collapse

WHO =
'cpee'
TYPE =
'instance'

Class Method Summary collapse

Class Method Details

.send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cpee/message.rb', line 21

def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend)
  topic = ::File::dirname(event)
  name = ::File::basename(event)
  payload = {
    WHO => cpee,
    TYPE + '-url' => File.join(cpee,instance.to_s),
    TYPE => instance,
    'topic' => topic,
    'type' => type,
    'name' => name,
    'timestamp' =>  Time.now.xmlschema(3),
    'content' => content
  }
  payload[TYPE + '-uuid'] = instance_uuid if instance_uuid
  payload[TYPE + '-name'] = instance_name if instance_name
  backend.publish(type.to_s + ':' + event,
    instance.to_s + ' ' +
    JSON::generate(payload)
  )
end