Revision 89362181 snf-pithos-backend/pithos/backends/lib/rabbitmq/queue.py

b/snf-pithos-backend/pithos/backends/lib/rabbitmq/queue.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
import json
35
from hashlib import sha1
36
from random import random
37
from time import time
35 38

  
36 39
from synnefo.lib.amqp import AMQPClient
37
from synnefo.lib.queue import Receipt
40

  
41

  
42
class Message(object):
43
    def __init__(self, client, user, instance, resource, value, details={}):
44
        self.eventVersion = '1.0'
45
        self.occurredMillis = int(time() * 1000)
46
        self.receivedMillis = self.occurredMillis
47
        self.clientID = client
48
        self.userID = user
49
        self.instanceID = instance
50
        self.resource = resource
51
        self.value = value
52
        self.details = details
53
        hash = sha1()
54
        hash.update(json.dumps(
55
            [client, user, resource, value, details, random()]))
56
        self.id = hash.hexdigest()
57

  
38 58

  
39 59
class Queue(object):
40 60
    """Queue.
......
53 73
                                     type='topic')
54 74

  
55 75
    def send(self, message_key, user, instance, resource, value, details):
56
        body = Receipt(self.client_id, user, instance, resource, value, details).format()
76
        body = Message(
77
            self.client_id, user, instance, resource, value, details)
57 78
        self.client.basic_publish(exchange=self.exchange,
58 79
                                  routing_key=message_key,
59
                                  body=json.dumps(body))
60
    
80
                                  body=json.dumps(body.__dict__))
81

  
61 82
    def close(self):
62 83
        self.client.close()

Also available in: Unified diff