Skip to content
This repository was archived by the owner on Mar 9, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/snippets/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def publish_messages_with_custom_attributes(project_id, topic_id):


def publish_messages_with_error_handler(project_id, topic_id):
# [START pubsub_publish_messages_error_handler]
# [START pubsub_publish_with_error_handler]
"""Publishes multiple messages to a Pub/Sub topic with an error handler."""
import time

Expand Down Expand Up @@ -173,7 +173,7 @@ def callback(f):
time.sleep(5)

print("Published message with error handler.")
# [END pubsub_publish_messages_error_handler]
# [END pubsub_publish_with_error_handler]


def publish_messages_with_batch_settings(project_id, topic_id):
Expand Down
7 changes: 0 additions & 7 deletions samples/snippets/quickstart/pub.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START pubsub_quickstart_pub_all]
import argparse
import time

# [START pubsub_quickstart_pub_deps]
from google.cloud import pubsub_v1

# [END pubsub_quickstart_pub_deps]


def get_callback(api_future, data, ref):
"""Wrap message data in the context of the callback function."""
Expand All @@ -48,10 +44,8 @@ def callback(api_future):

def pub(project_id, topic_id):
"""Publishes a message to a Pub/Sub topic."""
# [START pubsub_quickstart_pub_client]
# Initialize a Publisher client.
client = pubsub_v1.PublisherClient()
# [END pubsub_quickstart_pub_client]
# Create a fully qualified identifier in the form of
# `projects/{project_id}/topics/{topic_id}`
topic_path = client.topic_path(project_id, topic_id)
Expand Down Expand Up @@ -83,4 +77,3 @@ def pub(project_id, topic_id):
args = parser.parse_args()

pub(args.project_id, args.topic_id)
# [END pubsub_quickstart_pub_all]
7 changes: 0 additions & 7 deletions samples/snippets/quickstart/sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# [START pubsub_quickstart_sub_all]
import argparse

# [START pubsub_quickstart_sub_deps]
from google.cloud import pubsub_v1

# [END pubsub_quickstart_sub_deps]


def sub(project_id, subscription_id):
"""Receives messages from a Pub/Sub subscription."""
# [START pubsub_quickstart_sub_client]
# Initialize a Subscriber client
subscriber_client = pubsub_v1.SubscriberClient()
# [END pubsub_quickstart_sub_client]
# Create a fully qualified identifier in the form of
# `projects/{project_id}/subscriptions/{subscription_id}`
subscription_path = subscriber_client.subscription_path(project_id, subscription_id)
Expand Down Expand Up @@ -66,4 +60,3 @@ def callback(message):
args = parser.parse_args()

sub(args.project_id, args.subscription_id)
# [END pubsub_quickstart_sub_all]