Destinations
GCP Pub/Sub
Publish events to a Google Cloud Pub/Sub topic.
Configuration
Config
| Field | Type | Required | Description |
|---|---|---|---|
config.project_id | string | Yes | GCP project ID |
config.topic | string | Yes | Pub/Sub topic name |
config.endpoint | string | No | Custom endpoint (for emulator) |
Credentials
| Field | Type | Required | Description |
|---|---|---|---|
credentials.service_account_json | string | Yes* | Service account JSON key |
*Not required when using the Pub/Sub emulator.
Example
sh
Message Format
Events are published as Pub/Sub messages with:
- Data: The event's
datafield (JSON) - Attributes: Event metadata
Example Message
If you publish an event:
json
Data:
json
Attributes:
Attributes include system metadata and any event metadata from the published event:
| Attribute | Source | Description |
|---|---|---|
event-id | System | The unique event ID |
topic | System | The event topic |
timestamp | System | Event timestamp (Unix) |
* | Event | Any additional metadata from the published event's metadata field |
IAM Permissions
The service account needs the following role:
roles/pubsub.publisheron the topic
Or the specific permission:
pubsub.topics.publish
Creating a Service Account
- Navigate to IAM & Admin > Service Accounts in the GCP Console
- Click Create Service Account
- Grant the Pub/Sub Publisher role
- Create a JSON key and download it
- Use the JSON content as
service_account_json
Using with Emulator
For local development with the Pub/Sub emulator, set the config.endpoint field:
json
When using the emulator, service_account_json is not required.