Skip to content

Instantly share code, notes, and snippets.

@under0tech
Created October 3, 2022 18:32
Show Gist options
  • Save under0tech/a5eaab83b880328050f3febdc7d998d6 to your computer and use it in GitHub Desktop.
Save under0tech/a5eaab83b880328050f3febdc7d998d6 to your computer and use it in GitHub Desktop.
# Load data from Pub/Sub infrastructure
def LoadSub(sub_name):
data = []
subscriber = pubsub_v1.SubscriberClient(credentials=credentials)
subscription_path = subscriber.subscription_path(PUBSUB_PROJECT_ID, sub_name)
def callback(message: pubsub_v1.subscriber.message.Message):
data.append(message)
streaming_pull_future = subscriber \
.subscribe(subscription_path, callback=callback)
with subscriber:
try:
streaming_pull_future.result(timeout=PUBSUB_TIMEOUT)
except TimeoutError:
streaming_pull_future.cancel()
streaming_pull_future.result()
return data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment