Consume messages from Google Cloud Pub/Sub reliably with at-least-once delivery, correct ack deadlines, and a dead-letter topic

domain: gcp-pubsub · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a subscription with a pull or push delivery type; set ackDeadlineSeconds to slightly longer than your worst-case processing time (maximum is 600 seconds)
  2. When pulling, use the streaming pull client (StreamingPull RPC) rather than synchronous pull for throughput; acknowledge each message by message ID before the ack deadline expires
  3. Extend the ack deadline mid-processing by calling ModifyAckDeadline if processing may exceed the initial deadline; most client libraries do this automatically when auto-ack extension is enabled
  4. Configure a dead-letter topic on the subscription by setting deadLetterPolicy.deadLetterTopic to a separate topic and deadLetterPolicy.maxDeliveryAttempts (5–100); failed messages are forwarded after that many unacknowledged deliveries
  5. Grant the Pub/Sub service account the roles/pubsub.publisher role on the dead-letter topic and roles/pubsub.subscriber on the original subscription so the service can forward and nack messages automatically
  6. Monitor the subscription/oldest_unacked_message_age and subscription/dead_letter_message_count Cloud Monitoring metrics to detect processing lag and DLQ build-up

Known gotchas

Related routes

Enable Google Pub/Sub exactly-once delivery on a subscription
cloud.google.com · 5 steps · unrated
Publish and consume Google Pub/Sub messages with ordering keys
cloud.google.com · 5 steps · unrated
Configure Google Pub/Sub push subscription with ordering keys and dead-letter topic
gcp-pubsub · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans