PubSub API
Simplified Google Cloud Pub/Sub wrapper with automatic retries and message archiving.
What It Does
The PubSub API provides a simplified interface for publish-subscribe messaging using Google Cloud Pub/Sub. It enables applications to send messages to topics and subscribe to them with automatic retry logic, message archiving, and intelligent message parsing that handles multiple encoding formats.
Key Capabilities
| Capability | Description |
|---|---|
| Message Publishing | Publish messages to Pub/Sub topics with automatic retries |
| Automatic Archiving | Optional message archiving to audit trail topic |
| Retry Logic | Exponential backoff with up to 5 retry attempts |
| Subscription Management | Manage topic subscriptions and message handlers |
| Intelligent Parsing | Automatic message parsing for multiple encoding formats |
| Ordering Support | Message ordering via ordering keys |
| Topic Reachability | Check if topics exist and are accessible |
| Mock Support | Testing mock for unit tests |
| Buffer Encoding | Handles Buffer-encoded messages (default Pub/Sub format) |
| Multiple Handlers | Support multiple handlers per topic subscription |
Configuration
Constants
- ARCHIVE_TOPIC_NAME: ‘engineering11_payload_archive’
- MAX_ATTEMPTS: 5 (retry attempts)
Archive Topic
- Automatic creation if not exists
- Stores complete message metadata
- UUID-based message IDs
Exports
Services
PubSubService- Main publishing serviceMockPubsubService- Testing mockPubSubSubscriptionManager- Subscription management
Functions
parsePubsubMessage()- Message parser
Types
Event<T>- Generic event typeUpdatedEvent<T>- Update event typeCloudFunctionEvent<T>- Cloud Function eventIEvent,IUpdatedEvent<T>- Deprecated types
Constants
CONSTANTS- Configuration constants
Common Use Cases
- Event-driven architecture: Publish events between microservices
- Async job processing: Queue jobs for background processing
- Data pipeline: Stream data between processing stages
- Notification delivery: Send notifications to subscribers
- Audit logging: Archive all messages for compliance
- Real-time updates: Push updates to subscribers
- Webhook delivery: Reliably deliver webhooks
- Message broadcasting: Send to multiple subscribers
Roadmap
Multi-Cloud Support
This API currently supports Google Cloud Platform. Future versions will add support for additional cloud providers and container-based deployment options, enabling greater flexibility in infrastructure choices.
What Customers Don’t Have to Build
- Google Cloud Pub/Sub integration
- Exponential backoff retry logic
- Message archiving infrastructure
- Intelligent message parsing
- Buffer and encoding handling
- Subscription management
- Topic reachability checking
- Message ordering support
- Error standardization
- Connection lifecycle management
- Mock service for testing
- Event type definitions
- Protobuf message parsing
- JSON message parsing
- Handler registration system
- Multi-handler support per topic
- Graceful shutdown logic
- Archive topic management
Last updated on