3
from lqs import LQSServer, LQSMessage
5
from boto.sqs.jsonmessage import JSONMessage
9
def __init__(self, host):
11
self.port = LQSServer.PORT
12
self.timeout = LQSServer.TIMEOUT
13
self.max_len = LQSServer.MAXSIZE
17
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
18
self.sock.settimeout(self.timeout)
19
self.sock.connect((self.host, self.port))
21
def decode(self, jsonstr):
22
return LQSMessage(jsonvalue=jsonstr)
25
self.sock.send('next')
27
jsonstr = self.sock.recv(self.max_len)
28
msg = LQSMessage(jsonvalue=jsonstr)
31
print "recv from %s failed" % self.host
33
def delete(self, msg):
34
self.sock.send('delete %s' % msg['id'])
36
jsonstr = self.sock.recv(self.max_len)
37
msg = LQSMessage(jsonvalue=jsonstr)
40
print "recv from %s failed" % self.host
47
def __init__(self, queue_name):
48
self.queue_name = queue_name
51
self.queue = boto.lookup('sqs', self.queue_name)
52
self.queue.set_mesasge_class(JSONMessage)
62
if name == 'localhost':
63
return LQSClient(name)
65
return SQSClient(name)