Cloud Pub/Sub API Connector Overview

The Workflows connector defines the built-in functions that can be used to access other Google Cloud products within a workflow.

This page provides an overview of the individual connector. There is no need to import or load connector libraries in a workflow—connectors work out of the box when used in a call step.

Cloud Pub/Sub API

Provides reliable, many-to-many, asynchronous messaging between applications. To learn more, see the Cloud Pub/Sub API documentation.

This connector supports Pub/Sub operations, including publishing messages. You can also trigger an execution of a workflow using messages published to a Pub/Sub topic.

Cloud Pub/Sub connector sample

YAML

# This workflow demonstrates how to use the Cloud Pub/Sub connector.
# The workflow creates a Pub/Sub topic, a new subscription to that new topic, publishes a new message to
# the topic, pulls the message from the subscription, and then deletes both
# the subscription and the topic.
# Expected successful output: "SUCCESS"

- init:
    assign:
      - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
      - topic: "[fill in a Pubsub topic name]"
      - subscription: "[fill in a Pubsub subscription name]"
      - message: {"hello": "world"}  # An object used as a secret.
      - base64Msg: ${base64.encode(json.encode(message))}
- create_topic:
    call: googleapis.pubsub.v1.projects.topics.create
    args:
      name: ${"projects/" + project + "/topics/" + topic}
- create_subscription_to_topic:
    call: googleapis.pubsub.v1.projects.subscriptions.create
    args:
      name: ${"projects/" + project + "/subscriptions/" + subscription}
      body:
        name: ${"projects/" + project + "/subscriptions/" + subscription}
        topic: ${"projects/" + project + "/topics/" + topic}
- publish_message_to_topic:
    call: googleapis.pubsub.v1.projects.topics.publish
    args:
      topic: ${"projects/" + project + "/topics/" + topic}
      body:
        messages:
          - data: ${base64Msg}
- pull_message:
    call: googleapis.pubsub.v1.projects.subscriptions.pull
    args:
      subscription: ${"projects/" + project + "/subscriptions/" + subscription}
      body:
        maxMessages: 1
    result: m
- check_message:
    switch:
      - condition: ${m.receivedMessages[0].message.data != base64Msg}
        next: failed
- delete_subscription:
    call: googleapis.pubsub.v1.projects.subscriptions.delete
    args:
      subscription: ${"projects/" + project + "/subscriptions/" + subscription}
- delete_topic:
    call: googleapis.pubsub.v1.projects.topics.delete
    args:
      topic: ${"projects/" + project + "/topics/" + topic}
- the_end:
    return: "SUCCESS"
- failed:
    raise: ${"got data:" + m.receivedMessages[0].message.data + " want data:" + base64Msg}

JSON

[
  {
    "init": {
      "assign": [
        {
          "project": "${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}"
        },
        {
          "topic": "[fill in a Pubsub topic name]"
        },
        {
          "subscription": "[fill in a Pubsub subscription name]"
        },
        {
          "message": {
            "hello": "world"
          }
        },
        {
          "base64Msg": "${base64.encode(json.encode(message))}"
        }
      ]
    }
  },
  {
    "create_topic": {
      "call": "googleapis.pubsub.v1.projects.topics.create",
      "args": {
        "name": "${\"projects/\" + project + \"/topics/\" + topic}"
      }
    }
  },
  {
    "create_subscription_to_topic": {
      "call": "googleapis.pubsub.v1.projects.subscriptions.create",
      "args": {
        "name": "${\"projects/\" + project + \"/subscriptions/\" + subscription}",
        "body": {
          "name": "${\"projects/\" + project + \"/subscriptions/\" + subscription}",
          "topic": "${\"projects/\" + project + \"/topics/\" + topic}"
        }
      }
    }
  },
  {
    "publish_message_to_topic": {
      "call": "googleapis.pubsub.v1.projects.topics.publish",
      "args": {
        "topic": "${\"projects/\" + project + \"/topics/\" + topic}",
        "body": {
          "messages": [
            {
              "data": "${base64Msg}"
            }
          ]
        }
      }
    }
  },
  {
    "pull_message": {
      "call": "googleapis.pubsub.v1.projects.subscriptions.pull",
      "args": {
        "subscription": "${\"projects/\" + project + \"/subscriptions/\" + subscription}",
        "body": {
          "maxMessages": 1
        }
      },
      "result": "m"
    }
  },
  {
    "check_message": {
      "switch": [
        {
          "condition": "${m.receivedMessages[0].message.data != base64Msg}",
          "next": "failed"
        }
      ]
    }
  },
  {
    "delete_subscription": {
      "call": "googleapis.pubsub.v1.projects.subscriptions.delete",
      "args": {
        "subscription": "${\"projects/\" + project + \"/subscriptions/\" + subscription}"
      }
    }
  },
  {
    "delete_topic": {
      "call": "googleapis.pubsub.v1.projects.topics.delete",
      "args": {
        "topic": "${\"projects/\" + project + \"/topics/\" + topic}"
      }
    }
  },
  {
    "the_end": {
      "return": "SUCCESS"
    }
  },
  {
    "failed": {
      "raise": "${\"got data:\" + m.receivedMessages[0].message.data + \" want data:\" + base64Msg}"
    }
  }
]

Module: googleapis.pubsub.v1.projects.schemas

Functions
create Creates a schema.
delete Deletes a schema.
get Gets a schema.
list Lists schemas in a project.
validate Validates a schema.
validateMessage Validates a message against a schema.

Module: googleapis.pubsub.v1.projects.snapshots

Functions
create Creates a snapshot from the requested subscription. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. If the snapshot already exists, returns ALREADY_EXISTS. If the requested subscription doesn't exist, returns NOT_FOUND. If the backlog in the subscription is too old -- and the resulting snapshot would expire in less than 1 hour -- then FAILED_PRECONDITION is returned. See also the Snapshot.expire_time field. If the name is not provided in the request, the server will assign a random name for this snapshot on the same project as the subscription, conforming to the resource name format. The generated name is populated in the returned Snapshot object. Note that for REST API requests, you must specify a name in the request.
delete Removes an existing snapshot. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. When the snapshot is deleted, all messages retained in the snapshot are immediately dropped. After a snapshot is deleted, a new one may be created with the same name, but the new one has no association with the old snapshot or its subscription, unless the same subscription is specified.
getIamPolicy Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
list Lists the existing snapshots. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
patch Updates an existing snapshot. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.
setIamPolicy Sets the access control policy on the specified resource. Replaces any existing policy. Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
testIamPermissions Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Module: googleapis.pubsub.v1.projects.subscriptions

Functions
acknowledge Acknowledges the messages associated with the ack_ids in the AcknowledgeRequest. The Pub/Sub system can remove the relevant messages from the subscription. Acknowledging a message whose ack deadline has expired may succeed, but such a message may be redelivered later. Acknowledging a message more than once will not result in an error.
create Creates a subscription to a given topic. See the resource name rules. If the subscription already exists, returns ALREADY_EXISTS. If the corresponding topic doesn't exist, returns NOT_FOUND. If the name is not provided in the request, the server will assign a random name for this subscription on the same project as the topic, conforming to the resource name format. The generated name is populated in the returned Subscription object. Note that for REST API requests, you must specify a name in the request.
delete Deletes an existing subscription. All messages retained in the subscription are immediately dropped. Calls to Pull after deletion will return NOT_FOUND. After a subscription is deleted, a new one may be created with the same name, but the new one has no association with the old subscription or its topic unless the same topic is specified.
detach Detaches a subscription from this topic. All messages retained in the subscription are dropped. Subsequent Pull and StreamingPull requests will return FAILED_PRECONDITION. If the subscription is a push subscription, pushes to the endpoint will stop.
get Gets the configuration details of a subscription.
getIamPolicy Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
list Lists matching subscriptions.
modifyAckDeadline Modifies the ack deadline for a specific message. This method is useful to indicate that more time is needed to process a message by the subscriber, or to make the message available for redelivery if the processing was interrupted. Note that this does not modify the subscription-level ackDeadlineSeconds used for subsequent messages.
modifyPushConfig Modifies the PushConfig for a specified subscription. This may be used to change a push subscription to a pull one (signified by an empty PushConfig) or vice versa, or change the endpoint URL and other attributes of a push subscription. Messages will accumulate for delivery continuously through the call regardless of changes to the PushConfig.
patch Updates an existing subscription. Note that certain properties of a subscription, such as its topic, are not modifiable.
pull Pulls messages from the server. The server may return UNAVAILABLE if there are too many concurrent pull requests pending for the given subscription.
seek Seeks an existing subscription to a point in time or to a given snapshot, whichever is provided in the request. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot. Note that both the subscription and the snapshot must be on the same topic.
setIamPolicy Sets the access control policy on the specified resource. Replaces any existing policy. Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
testIamPermissions Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Module: googleapis.pubsub.v1.projects.topics

Functions
create Creates the given topic with the given name. See the resource name rules.
delete Deletes the topic with the given name. Returns NOT_FOUND if the topic does not exist. After a topic is deleted, a new topic may be created with the same name; this is an entirely new topic with none of the old configuration or subscriptions. Existing subscriptions to this topic are not deleted, but their topic field is set to _deleted-topic_.
get Gets the configuration of a topic.
getIamPolicy Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.
list Lists matching topics.
patch Updates an existing topic. Note that certain properties of a topic are not modifiable.
publish Adds one or more messages to the topic. Returns NOT_FOUND if the topic does not exist.
setIamPolicy Sets the access control policy on the specified resource. Replaces any existing policy. Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED errors.
testIamPermissions Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error. Note: This operation is designed to be used for building permission-aware UIs and command-line tools, not for authorization checking. This operation may "fail open" without warning.

Module: googleapis.pubsub.v1.projects.topics.snapshots

Functions
list Lists the names of the snapshots on this topic. Snapshots are used in Seek operations, which allow you to manage message acknowledgments in bulk. That is, you can set the acknowledgment state of messages in an existing subscription to the state captured by a snapshot.

Module: googleapis.pubsub.v1.projects.topics.subscriptions

Functions
list Lists the names of the attached subscriptions on this topic.