Use pop for checking messages with websocket

I1c94ad82c3b20cc331045c19d4a9987a701b081b fixed the issue in Zaqar where
the pop argument was wrongly named. We can now use it in the zaqar
collector to retrieve messages over websocket.

Change-Id: I0ce894b0eef7018a37db9ef9d1b43d8d20629bf0
This commit is contained in:
Thomas Herve 2017-01-09 10:58:23 +01:00
parent cb846967f7
commit 432abd47ec
1 changed files with 4 additions and 12 deletions

View File

@ -90,27 +90,19 @@ class Collector(object):
'ttl': 10000})
ws.send(req)
# TODO(dprince) would be nice to use message_delete_many but
# websockets doesn't support parameters so we can't send 'pop'.
# This would allow us to avoid the 'message_delete' below. Example:
# req = self._create_req(endpoint, 'message_delete_many',
# {'queue_name': CONF.zaqar.queue_id, 'pop': 1})
req = self._create_req(endpoint, 'message_list',
# check for pre-existing messages
req = self._create_req(endpoint, 'message_delete_many',
{'queue_name': CONF.zaqar.queue_id,
'echo': True})
'pop': 1})
resp = ws.send(req)
messages = json.loads(resp.content).get('messages', [])
if len(messages) > 0:
# NOTE(dprince) In this case we are checking for queue
# messages that arrived before we subscribed.
logger.debug('Websocket message_list found...')
logger.debug('Websocket message found...')
msg_0 = messages[0]
data = msg_0['body']
req = self._create_req(endpoint, 'message_delete',
{'queue_name': CONF.zaqar.queue_id,
'message_id': msg_0['id']})
ws.send(req)
else:
# NOTE(dprince) This will block until there is data available