Google Cloud Pub/Sub
Synopsis
Creates a target that publishes messages to Google Cloud Pub/Sub topics with support for batch processing, message ordering, and service account authentication. Provides reliable message delivery to Google Cloud Pub/Sub for event-driven architectures and distributed systems.
Schema
- name: <string>
description: <string>
type: gcppubsub
pipelines: <pipeline[]>
status: <boolean>
properties:
project_id: <string>
topic_id: <string>
credentials_file: <string>
credentials_json: <string>
ordering_key: <string>
max_messages: <numeric>
max_bytes: <numeric>
field_format: <string>
interval: <string|numeric>
cron: <string>
debug:
status: <boolean>
dont_send_logs: <boolean>
Configuration
The following fields are used to define the target:
| Field | Required | Default | Description |
|---|---|---|---|
name | Y | Target name | |
description | N | - | Optional description |
type | Y | Must be gcppubsub | |
pipelines | N | - | Optional post-processor pipelines |
status | N | true | Enable/disable the target |
Connection
| Field | Required | Default | Description |
|---|---|---|---|
project_id | Y | - | Google Cloud project ID |
topic_id | Y | - | Pub/Sub topic ID |
credentials_file | N* | - | Path to service account JSON key file |
credentials_json | N* | - | Service account JSON key as string |
* = Either credentials_file or credentials_json must be provided.
Service account must have roles/pubsub.publisher permission on the topic.
Message Configuration
| Field | Required | Default | Description |
|---|---|---|---|
ordering_key | N | - | Ordering key for message ordering within the topic |
max_messages | N | 1000 | Maximum number of messages per batch |
max_bytes | N | 10485760 | Maximum batch size in bytes (10 MB) |
field_format | N | - | Data normalization format. See applicable Normalization section |
Scheduler
| Field | Required | Default | Description |
|---|---|---|---|
interval | N | realtime | Execution frequency. See Interval for details |
cron | N | - | Cron expression for scheduled execution. See Cron for details |
Debug Options
| Field | Required | Default | Description |
|---|---|---|---|
debug.status | N | false | Enable debug logging |
debug.dont_send_logs | N | false | Process logs but don't send to target (testing) |
Details
The Google Cloud Pub/Sub target publishes messages to Pub/Sub topics for asynchronous, scalable message delivery. It supports batch processing for optimal performance and message ordering for maintaining event sequence.
Authentication
Authentication uses Google Cloud service account credentials. You can provide credentials either as a file path or as a JSON string.
IAM Permissions
The service account requires the following IAM role:
| IAM Role | Role ID | Purpose |
|---|---|---|
Pub/Sub Editor | roles/pubsub.editor | Check, create topics and publish messages |
If the topic is pre-created and auto-creation is not needed, a narrower set of roles can be used:
| IAM Role | Role ID | Purpose |
|---|---|---|
Pub/Sub Publisher | roles/pubsub.publisher | Publish messages to existing topic |
Pub/Sub Viewer | roles/pubsub.viewer | Check topic existence |
Minimum permissions: pubsub.topics.get, pubsub.topics.create (optional), pubsub.topics.publish
Topic Management
The target automatically checks if the specified topic exists and creates it if needed. Topics are created in the specified Google Cloud project.
Message Ordering
When an ordering_key is set, Pub/Sub ensures that messages with the same ordering key are delivered in the order they were published. This is useful for maintaining event sequences for specific entities.
Example: Use device ID as ordering key to ensure events from the same device are processed in order.
Message Attributes
The target automatically adds the following attributes to each message:
device_id- Source device identifierdevice_type- Type of source devicedevice_name- Name of source device
These attributes can be used for message filtering and routing in subscriptions.
Batch Processing
Messages are published in batches for optimal throughput. The target accumulates messages until the batch size limit is reached or during finalization. Google Cloud Pub/Sub supports up to 10 MB per batch.
At-Least-Once Delivery
Pub/Sub guarantees at-least-once delivery. Messages may be delivered more than once in case of network issues or subscriber failures. Design your message handlers to be idempotent.
Message Retention
Messages are retained for 7 days by default. You can configure retention periods from 10 minutes to 7 days in the topic settings.
Dead Letter Topics
Google Cloud Pub/Sub supports dead letter topics for messages that cannot be processed after a configured number of delivery attempts. Configure this in the subscription settings.
Examples
The following are commonly used configuration types.
Basic with File Credentials
Creating a basic Pub/Sub target with credentials file... | |
Target publishes JSON messages to Pub/Sub topic... | |
With JSON Credentials
Using credentials as JSON string (useful for secrets management)... | |
With Message Ordering
Using ordering key to maintain message sequence... | |
High-Throughput Configuration
Optimizing for high-volume message publishing... | |
Multiple Topics
Publishing to different topics for different log types... | |
Field Normalization
Using field normalization for standard format... | |
Pipeline Processing
Applying post-processing pipelines before publishing... | |
Scheduled Batching
Configuration with scheduled batch delivery... | |
Debug Configuration
Configuration with debugging enabled... | |
Production Configuration
Configuration for production with optimal settings... | |