I'm trying to set up two different google pub/sub subscribers to different subscriptions but in the same code. To paint a better picture say I have topic1 and topic2. Then I have subscription1 which is subscribed to topic1 and subscription2 which is subscribed to topic2. Then I have subscriber1 which is linked to subscription1 and subscriber2 which is linked to subscription2. My question is how can I use subscriber1 and subscriber2 in the same application. My example for just 1 subscriber is (from documentation):
project_id = "my-project-id"
subscription_id = "subscription1"
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(project_id, subscription_id)
streaming_pull_future = subscriber.subscribe(subscription_path, callback=callback)
logging.info("Listening for messages on {}..\n".format(subscription_path))
# Wrap subscriber in a 'with' block to automatically call close() when done.
with subscriber:
try:
# When `timeout` is not set, result() will block indefinitely,
# unless an exception is encountered first.
streaming_pull_future.result()
except TimeoutError:
streaming_pull_future.cancel()
How can I add subscription2 into this so that my python application can get messages from both topic1 and topic2? I couldn't find it in the docs but if I'm just missing it somehow let me know!