Destinations

GCP Pub/Sub

Publish events to a Google Cloud Pub/Sub topic.

Configuration

Config

FieldTypeRequiredDescription
config.project_idstringYesGCP project ID
config.topicstringYesPub/Sub topic name
config.endpointstringNoCustom endpoint (for emulator)

Credentials

FieldTypeRequiredDescription
credentials.service_account_jsonstringYes*Service account JSON key

*Not required when using the Pub/Sub emulator.

Example

curl --location 'https://<OUTPOST_API_URL>/api/v1/<TENANT_ID>/destinations' \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer <API_KEY>' \ --data '{ "type": "gcp_pubsub", "topics": ["orders"], "config": { "project_id": "my-project", "topic": "my-topic" }, "credentials": { "service_account_json": "{\"type\": \"service_account\", ...}" } }'
sh

Message Format

Events are published as Pub/Sub messages with:

  • Data: The event's data field (JSON)
  • Attributes: Event metadata

Example Message

If you publish an event:

{ "topic": "orders", "data": { "order_id": "123", "status": "created" }, "metadata": { "source": "checkout-service" } }
json

Data:

{ "order_id": "123", "status": "created" }
json

Attributes:

Attributes include system metadata and any event metadata from the published event:

AttributeSourceDescription
event-idSystemThe unique event ID
topicSystemThe event topic
timestampSystemEvent timestamp (Unix)
*EventAny additional metadata from the published event's metadata field

IAM Permissions

The service account needs the following role:

  • roles/pubsub.publisher on the topic

Or the specific permission:

  • pubsub.topics.publish

Creating a Service Account

  1. Navigate to IAM & Admin > Service Accounts in the GCP Console
  2. Click Create Service Account
  3. Grant the Pub/Sub Publisher role
  4. Create a JSON key and download it
  5. Use the JSON content as service_account_json

Using with Emulator

For local development with the Pub/Sub emulator, set the config.endpoint field:

{ "type": "gcp_pubsub", "topics": ["orders"], "config": { "project_id": "test-project", "topic": "test-topic", "endpoint": "localhost:8085" } }
json

When using the emulator, service_account_json is not required.