dawiddutoit/custom-claude/gcp-pubsub

Claude Code and agent skill by dawiddutoit/custom-claude

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Implements Google Cloud Pub/Sub integration in Python by configuring topics, subscriptions, publishing/subscribing, dead letter queues, and local emulator setup. Use when building event-driven architectures, implementing message queuing, or managing high-throughput systems. Triggers on "setup Pub/Sub", "publish messages", "create subscription", "configure DLQ", or "test with emulator". Works with google-cloud-pubsub library and includes reliability, idempotency, and testing patterns.

Install

npx vskill@latest install dawiddutoit/custom-claude/gcp-pubsub

SKILL.md

Google Cloud Pub/Sub

Table of Contents

Purpose

Build robust, production-ready event-driven systems using Google Cloud Pub/Sub with Python. Covers setup, publishing, subscribing, error handling, dead letter queues, and local development with the emulator.

When to Use

Use this skill when you need to:

  • Build event-driven architectures with message-based communication
  • Implement reliable message queuing between services
  • Handle at-least-once message delivery guarantees
  • Manage high-throughput message systems (1000+ msgs/sec)
  • Configure local development with Pub/Sub emulator
  • Implement dead letter queues for failed message handling

Quick Start

Install and authenticate:

bash
pip install google-cloud-pubsub
gcloud auth application-default login
python -c "from google.cloud import pubsub_v1; print('Ready')"

Publish a message:

python
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path("my-project", "my-topic")
# Create topic
try:
publisher.create_topic(request={"name": topic_path})
except Exception as e:
if "ALREADY_EXISTS" not in str(e):
raise
# Publish
future = publisher.publish(topic_path, b"Hello, World!")
print(f"Published: {future.result()}")

Subscribe to messages:

python
from google.cloud import pubsub_v1
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path("my-project", "my-subscription")
def callback(message):
print(f"Received: {message.data.decode()}")
message.ack()
future = subscriber.subscribe(subscription_path, callback=callback)
try:
future.result(timeout=30)
except Exception:
future.cancel()

Instructions

Step 1: Set Up Development Environment

Install dependencies and configure authentication:

bash
pip install google-cloud-pubsub
gcloud auth application-default login

For production, use service account:

bash
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account-key.json"
Step 2: Create Topics and Subscriptions
python
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
subscriber = pubsub_v1.SubscriberClient()
# Create topic
topic_path = publisher.topic_path("my-project", "my-topic")
publisher.create_topic(request={"name": topic_path})
# Create subscription
subscription_path = subscriber.subscription_path("my-project", "my-subscription")
subscription_config = {
"name": subscription_path,
"topic": topic_path,
"ack_deadline_seconds": 60,
}
subscriber.create_subscription(request=subscription_config)

See references/detailed-guide.md for advanced configuration options.

Step 3: Publish Messages

Simple publishing:

python
from google.cloud import pubsub_v1
publisher = pubsub_v1.PublisherClient()
topic_path = publisher.topic_path("my-project", "my-topic")
future = publisher.publish(topic_path, b"Message data")
message_id = future.result()

Publish with attributes:

python
import json
data = json.dumps({"event": "user.created", "user_id": "123"}).encode()
future = publisher.publish(
topic_path,
data,
event_type="user.created",
timestamp="2024-01-15T10:30:00Z"
)

See references/detailed-guide.md for production-ready publisher with batching and error handling.

Step 4: Subscribe to Messages

Basic subscriber:

python
from google.cloud import pubsub_v1
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path("my-project", "my-subscription")
def callback(message):
try:
print(f"Received: {message.data.decode()}")
# Process message
message.ack()
except Exception as e:
print(f"Error: {e}")
message.nack() # Will be redelivered
future = subscriber.subscribe(subscription_path, callback=callback)
try:
future.result() # Block indefinitely
except KeyboardInterrupt:
future.cancel()

With flow control:

python
future = subscriber.subscribe(
subscription_path,
callback=callback,
flow_control=pubsub_v1.types.FlowControl(
max_messages=100,
max_bytes=100 * 1024 * 1024, # 100 MB
),
)

See references/detailed-guide.md for production subscriber with monitoring.

Step 5: Configure Dead Letter Queue
python
from google.cloud import pubsub_v1
from google.protobuf.duration_pb2 import Duration
publisher = pubsub_v1.PublisherClient()
subscriber = pubsub_v1.SubscriberClient()
# Create dead letter topic
dlq_topic_path = publisher.topic_path("my-project", "my-topic-dlq")
publisher.create_topic(request={"name": dlq_topic_path})
# Create subscription with DLQ
subscription_path = subscriber.subscription_path("my-project", "my-subscription")
subscription = pubsub_v1.types.Subscription(
name=subscription_path,
topic=publisher.topic_path("my-project", "my-topic"),
dead_letter_policy=pubsub_v1.types.DeadLetterPolicy(
dead_letter_topic=dlq_topic_path,
max_delivery_attempts=5,
),
retry_policy=pubsub_v1.types.RetryPolicy(
minimum_backoff=Duration(seconds=10),
maximum_backoff=Duration(seconds=600),
),
)
subscriber.create_subscription(request=subscription)

See references/detailed-guide.md for complete DLQ setup with monitoring.

Step 6: Implement Idempotency

Track processed messages to avoid duplicate processing:

python
class IdempotentProcessor:
def __init__(self):
self.processed_ids = set()
def process(self, message):
msg_id = message.message_id
if msg_id in self.processed_ids:
print(f"Already processed: {msg_id}")
message.ack()
return
try:
# Process message
print(f"Processing: {message.data.decode()}")
self.processed_ids.add(msg_id)
message.ack()
except Exception as e:
print(f"Failed: {e}")
message.nack()

See references/detailed-guide.md for production-ready idempotency patterns.

Step 7: Local Development with Emulator
bash
# Install and start emulator
gcloud components install pubsub-emulator
gcloud beta emulators pubsub start
# In another terminal
export PUBSUB_EMULATOR_HOST=localhost:8085
python your_script.py # Uses emulator automatically

See references/detailed-guide.md for emulator configuration patterns.

Step 8: Monitor Operations

Enable logging and track metrics:

python
import logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
# Query subscription stats
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path("my-project", "my-subscription")
subscription = subscriber.get_subscription(request={"subscription": subscription_path})
print(f"Topic: {subscription.topic}")
print(f"Ack deadline: {subscription.ack_deadline_seconds}s")

See references/detailed-guide.md for comprehensive monitoring patterns.

Requirements

  • Python: 3.7+
  • Dependencies:

``bash pip install google-cloud-pubsub>=2.18.0 ``

  • GCP Project: Active project with Pub/Sub API enabled
  • Authentication: Application Default Credentials or service account key
  • IAM Permissions:
  • roles/pubsub.publisher - Publish messages
  • roles/pubsub.subscriber - Subscribe to messages
  • roles/pubsub.admin - Create/delete topics and subscriptions
  • For Local Development:

``bash gcloud components install pubsub-emulator ``

See Also

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
1
7-day trend score
3

Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 3 Apr 2026, 7 months ago.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dawiddutoit/custom-claude/gcp-pubsub/badge)](https://verified-skill.com/skills/dawiddutoit/custom-claude/gcp-pubsub)

Something wrong with this skill or its page? Tell us.