GCP Pub/Sub Subscriber icon

GCP Pub/Sub Subscriber

Subscribes to messages from a Google Cloud Pub/Sub subscription

Overview

This node subscribes to messages from a Google Cloud Pub/Sub subscription. It listens continuously for new messages published to a specified subscription within a Google Cloud project and outputs each message as it arrives. This is useful for real-time event-driven workflows where you want to trigger automation based on messages sent via Google Cloud Pub/Sub.

Common scenarios include:

  • Processing notifications or events published by other systems into Pub/Sub.
  • Triggering workflows when new data arrives asynchronously.
  • Integrating Google Cloud services with n8n through Pub/Sub messaging.

For example, you could use this node to listen for order updates published to a Pub/Sub topic and then process those orders automatically in your workflow.

Properties

Name Meaning
Project ID The Google Cloud Project ID where the Pub/Sub subscription exists.
Subscription Name The name of the Pub/Sub subscription to listen to for incoming messages.

Output

The node outputs an array of JSON objects, each representing a received Pub/Sub message with the following structure:

  • id: The unique identifier of the message.
  • attributes: Any attributes attached to the message (key-value pairs).
  • data: The message payload. If the payload is valid JSON, it is parsed into an object; otherwise, it is returned as a UTF-8 string.
  • publishTime: The timestamp when the message was published.
  • received: The ISO timestamp when the message was received by the node.

The node does not output binary data.

Dependencies

  • Requires a Google Cloud Pub/Sub service account API key credential with permissions to access the specified project and subscription.
  • The node uses the official @google-cloud/pubsub library to connect and listen to Pub/Sub subscriptions.
  • The user must provide valid Google Cloud Project ID and Subscription Name parameters.
  • Proper configuration of the Google Cloud Pub/Sub subscription and service account is necessary.

Troubleshooting

  • Missing Project ID or Subscription Name: The node will throw an error if either parameter is empty. Ensure both are provided.
  • Invalid Service Account JSON: If the service account credentials cannot be parsed, the node will fail. Verify that the JSON is correctly formatted and corresponds to a valid service account.
  • Subscription Errors: Runtime errors from the Pub/Sub subscription are logged. These may indicate network issues, permission problems, or misconfigured subscriptions.
  • Message Processing Errors: If a message cannot be processed (e.g., invalid JSON in payload), the node logs the error and negatively acknowledges the message to allow redelivery.

To resolve common errors:

  • Double-check all input parameters and credentials.
  • Confirm the service account has Pub/Sub Subscriber role on the project.
  • Ensure the subscription name matches exactly what exists in Google Cloud.
  • Review logs for detailed error messages.

Links and References

Discussion