Advertisement
Guest User

Untitled

a guest
May 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #coding=utf-8
  2. from google.gax.errors import GaxError
  3. from google.pubsub.v1.subscriber_api import SubscriberApi
  4. from grpc.framework.interfaces.face.face import ExpirationError
  5.  
  6.  
  7. def main():
  8. api = SubscriberApi(timeout=5)
  9. subscription = api.subscription_path(<project>, <subscription-name>)
  10.  
  11. for i in xrange(5):
  12. print('[PULL] Pull:ing data...')
  13. try:
  14. resp = api.pull(subscription, max_messages=5)
  15. except GaxError as e:
  16. if isinstance(e.cause, ExpirationError):
  17. print('[PULL] timed out!')
  18. continue
  19. raise e
  20. print(u'[PULL] ✉️ Got messages: {}'.format(resp))
  21. print(u'[ACK] Acknowledging ...')
  22. ack_ids = map(lambda msg: msg.ack_id, resp.received_messages)
  23. ackresp = api.acknowledge(subscription, ack_ids)
  24. print(u'[ACK] Done!')
  25. print('bye')
  26.  
  27. if __name__ == '__main__':
  28. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement