Google Cloud Pub/Sub Extension

Version: 1.2.0

Publish messages to a topic in the Google Cloud Pub/Sub service.

This content provides reference for configuring and using this extension.

Prerequisites

Before using this extension from an API proxy, you must:

  1. Create a Cloud Pub/Sub topic, as described in Quickstart: Using the console.

  2. Once you have the topic, grant permission to publish to your Cloud Pub/Sub topic. For example, you can use the roles/pubsub.publisher role to publish to topics. For more on Cloud Pub/Sub roles, see Access Control.

  3. Generate a key for the service account.

  4. Use the contents of the resulting key JSON file when adding and configuring the extension using the configuration reference.

About Cloud Pub/Sub

Cloud Pub/Sub provides many-to-many, asynchronous messaging that decouples senders and receivers. Cloud Pub/Sub delivers low-latency, durable messaging that helps developers quickly integrate systems hosted on the Google Cloud Platform and externally.

If you're just getting started with Cloud Pub/Sub, take a look at the quickstarts in the Cloud Pub/Sub documentation.

Samples

The following examples illustrate how to configure support for Cloud Pub/Sub extension actions using the ExtensionCallout policy.

Publish a message

In this example, the publish action publishes a simple message to a topic specified in the extension's configuration. The publish action returns the ID of the published message in the topic to which it was published.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="true" enabled="true" name="Publish-Message">
    <DisplayName>Publish Message</DisplayName>
    <Connector>cloud-pub-sub-extension-example</Connector>
    <Action>publish</Action>
    <Input><![CDATA[
      {
          "message" : "My test message."
      }
    ]]></Input>
    <Output>topic.message.id</Output>
</ConnectorCallout>

The following Assign Message policy uses the value of the variable storing the extension's response to assign the response payload.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Get-Topic-Message-ID">
    <DisplayName>Get Topic Message ID</DisplayName>
    <AssignTo type="response" createNew="false"/>
    <Set>
        <Payload contentType="application/json">{topic.message.id}</Payload>
    </Set>
</AssignMessage>

In this example, the response data is returned as JSON such as the following.

{"messageId":"165918654986954"}

Actions

publish

Publishes a message to the topic specified in this extension's configuration.

Syntax

<Action>publish</Action>
<Input><![CDATA[{
  "message" : "message-to-publish"
}]]></Input>

Example

<Action>publish</Action>
<Input><![CDATA[
  {
      "message" : "My test message."
  }
]]></Input>

Request parameters

Parameter Description Type Default Required
message The message to publish. String None. Yes.

Response

JSON containing the ID of the message as published to the topic. For example:

{"messageId":"165918654986954"}

Configuration Reference

Use the following when you're configuring and deploying this extension for use in API proxies.

Common extension properties

The following properties are present for every extension.

Property Description Default Required
name Name you're giving this configuration of the extension. None. Yes.
packageName Name of the extension package as given by Apigee Edge. None. Yes.
version Version number for the extension package from which you're configuring an extension. None. Yes.
configuration Configuration value specific to the extension you're adding. See Properties for this extension package None. Yes.

Properties for this extension package

Property Description Default Required
topic The topic to publish to. Get this value from the Pub/Sub service, such as from the GCP console for the service. For example, the topic name might take the form projects/GCP-PROJECT-ID/topics/TOPIC-NAME None. Yes.