Google PubSub

Google PubSub is a service that makes it easier to pass messages between machines and collect data from IoT devices.

The component interacts with Google Pub-Sub API. The API is an asynchronous messaging service that decouples services that produce events from services that process events. Pub/Sub offers durable message storage and real-time message delivery with high availability and consistent performance at scale. Pub/Sub servers run in all Google Cloud regions around the world.

Be aware of the idempotency of your processing flow. Below is an extract from the PubSub Subscriber Guide:

For the most part, Pub/Sub delivers each message once and in the order it was published. However, once-only and in-order delivery is not guaranteed: a message may be delivered more than once and out of order. Therefore, your subscriber should be idempotent when processing messages and, if necessary, able to handle messages received out of order. If ordering is necessary, we recommend that the publisher of the topic you subscribe include some sequence information in the message; Read Google’s ordering documentation for a complete discussion on message ordering. Messages that are not acknowledged are retried indefinitely for up to seven days.

— Google PubSub Subscriber Guide

Requirements

Core concepts

Topic

A named resource to which publishers send messages.

Subscription

A named resource representing the stream of messages from a specific topic to be delivered to the subscribing application. Read the Subscriber guide documentation for more information.

Message

The combination of data and, optionally, attributes that a publisher sends to a topic eventually delivers to subscribers.

Message attribute

A key-value pair that a publisher can define for a message. For example, the key iana.org/language_tag and the value en could be added to messages to mark them as readable by an English-speaking subscriber.

Credentials

  • Project ID

  • Client E-Mail

  • Private Key

Google provides a JSON file that includes your private key. Be careful using the information.

Follow the instructions use your credentials:

  1. Copy and paste the private key.

  2. Remove any line breakers (\n) from your key.

  3. Leave the two lines shown below as they are:

    -----BEGIN PRIVATE KEY-----
    YOUR KEY HERE
    -----END PRIVATE KEY-----

Authentication

PubSub component authentication works with Google IAM Service Accounts and two-legged OAuth. To authenticate your component, you need to create a new Service Account on the Service Accounts page of your project and download the JSON file with the private key.

You must have client_email and private_key values on the component authentication page.

Read the Using JWT service tokens documentation for more information.

The authentication mechanism requires access to the topics in your account to read and publish. Verifications will fail if your created service account has no read permission (to subscribe as a trigger function). Save the credential without verification and use it for publishing to the topics (as an action function).

Triggers

Subscribe

The Subscribe trigger receives a message from a topic, emits it, and sends an acknowledgment to Pub/Sub.

Configuration

Topic Name

The fully-qualified topic resource name string, for example, projects/<project_id>/topics/<topic_name>. This is a required field.

Actions

Publish

The Publish action retrieves the message body from a previous step and sends a message to a topic while remaining unaware of existing subscriptions.

Configuration

Configuration

Topic Name

The fully-qualified topic resource name string, for example, projects/<project_id>/topics/<topic_name>. This is a required field.