Created
October 3, 2022 18:32
-
-
Save under0tech/a5eaab83b880328050f3febdc7d998d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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