This document provides information about how to create, delete, and administer Pub/Sub topics and subscriptions. For more information about publishing and accessing message data, see the Publisher Guide and Subscriber Overview.
Managing Topics
You can create, delete, and view topics using the API,
the Google Cloud Console, or the gcloud
command-line tool. See the
gcloud pubsub
reference
for a complete list of Pub/Sub API gcloud
commands.
For an introduction to the Cloud Console, see the Cloud Console Quickstart.
When you create a topic, you can also specify your own encryption keys. See Using customer-managed encryption keys.
Creating a topic
You must first create a topic before you can publish or subscribe to it. Here is an example showing how to create a topic:
gcloud
gcloud pubsub topics create TOPIC_ID
REST
Request:
The request must be authenticated with an access token in the
Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
PUT https://pubsub.googleapis.com/v1/projects/myproject/topics/mytopic Authorization: Bearer ACCESS_TOKEN
Response:
200 OK
{ "name": "projects/myproject/topics/mytopic" }
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
Deleting a topic
Here is an example showing how to delete a topic:
gcloud
gcloud pubsub topics delete TOPIC_ID
REST
Request:
The request must be authenticated with an access token in the
Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
DELETE https://pubsub.googleapis.com/v1/projects/myproject/topics/mytopic Authorization: Bearer ACCESS_TOKEN
Response:
200 OK
{ "name": "projects/myproject/topics/mytopic" }
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
When you delete a topic, its subscriptions are not deleted, and the
subscription's message backlog is available for subscribers. After a topic is
deleted, its subscriptions have the topic name _deleted-topic_
. If you try
to create a topic with the same name as a topic you had just deleted, expect
an error for a brief period of time after the deletion.
Listing topics
Here is an example showing how to get a list of topics:
gcloud
gcloud pubsub topics list
REST
Request:
The request must be authenticated with an access token in the
Authorization
header. To obtain an access token for the current
Application Default Credentials: gcloud auth application-default print-access-token
.
GET https://pubsub.googleapis.com/v1/projects/myproject/topics Authorization: Bearer ACCESS_TOKEN
Response:
200 OK
{ "topics": [ { "name": "projects/myproject/topics/mytopic1" }, { "name": "projects/myproject/topics/mytopic2" } ] }
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
By default, a maximum of 100 results are returned per query. You can specify an alternative value up to 1,000 using the page size parameter.
Detaching subscriptions
When you create a subscription, you attach the subscription to a topic, and subscribers can receive messages from the subscription. To stop subscribers from receiving messages, you can detach subscriptions from the topic.
Before you detach a subscription, you need the
pubsub.topics.detachSubscription
permission on the topic. You can detach a
subscription without permissions on the subscription, which is useful for
managing a topic that is in a different project than the subscription. For
more information, see
Pub/Sub access control.
You can detach a subscription from a topic using the Cloud Console,
the gcloud
command-line tool, or the Pub/Sub API.
Console
To detach a subscription, follow these steps:
- In the Cloud Console, go to the Topics page.
- Click the topic ID.
- In the Subscriptions tab, click the subscription ID of the subscription to detach.
- In the Subscription details page, click Detach.
- In the dialog that appears, click Detach again.
gcloud
To detach a subscription, use the
gcloud pubsub topics detach-subscription
command:
gcloud pubsub topics detach-subscription SUBSCRIPTION_ID
If the request is successful, the command line displays a confirmation:
Detached subscription [SUBSCRIPTION_ID].
REST
To detach a subscription, send a request like the following:
POST https://pubsub.googleapis.com/v1/subscriptions/PROJECT_ID/subscriptions/SUBSCRIPTION_ID:detach Authorization: Bearer $(gcloud auth application-default print-access-token)
If the request is successful, the response is an empty JSON object.
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
The Pub/Sub service might take several minutes to finish detaching the subscription from the topic.
After the Pub/Sub service detaches the subscription from the topic, the Pub/Sub service deletes any messages that it retains for the subscription. You can't retrieve these messages from the subscription or reattach the subscription to a topic. To free up your Cloud project quota, delete the subscription.
If the subscription and the topic are in different Cloud projects, the Pub/Sub service adds an entry to the audit logs of both projects.
Managing Subscriptions
This section covers how to manage push and pull subscriptions. See the Subscriber Overview for an overview and comparison of pull and push subscriptions.
You must create a subscription to a topic before subscribers can receive messages published to the topic.
Creating subscriptions
When you create a subscription, you attach a topic to the subscription. Subscribers receive the messages that publishers send to this topic.
You can create subscriptions with the Cloud Console, gcloud
command-line tool,
or the Pub/Sub API.
Console
To create a subscription, complete the following steps.
- In the Cloud Console, go to the Subscriptions page.
- Click Create subscription.
- Enter the Subscription ID.
- Choose or create a topic from the drop-down menu. The subscription receives messages from the topic.
- Click Create.
You can also create a subscription from the Topics section. This shortcut is useful for associating topics with subscriptions.
- In the Cloud Console, go to the Topics page.
- Clickmore_vertnext to the topic on which to create a subscription.
- From the context menu, select Create subscription.
- Choose or create a topic from the drop-down menu. The subscription receives messages from the topic.
- Enter the Subscription ID.
- Click Create.
gcloud
To create a subscription, run the gcloud pubsub subscriptions create
command.
gcloud pubsub subscriptions create SUBSCRIPTION_ID \ --topic=TOPIC_ID \ [--ack-deadline=ACK_DEADLINE] \ [--dead-letter-topic=DEAD_LETTER_TOPIC_ID \ --dead-letter-topic-project=DEAD_LETTER_TOPIC_PROJECT_ID \ [--expiration-period=EXPIRATION_PERIOD] \ --max-delivery-attempts=MAX_DELIVERY_ATTEMPTS] \ [--message-filter=FILTER] [--message-retention-duration=MESSAGE_RETENTION_DURATION] \ [--max-retry-delay=MAX_RETRY_DELAY] \ [--min-retry-delay=MIN_RETRY_DELAY] \ [--push-endpoint=PUSH_ENDPOINT]
REST
Request:
The request must be authenticated with an access token in the Authorization
header. To obtain an access token for the current Application Default Credentials: gcloud auth application-default print-access-token.
PUT https://pubsub.googleapis.com/v1/projects/myproject/subscriptions/mysubscription Authorization: Bearer ACCESS_TOKEN
Specify the following fields in the request body:
{ "topic": "projects/someproject/topics/sometopic" // Only needed if you are using push delivery "pushConfig": { "pushEndpoint": "https://myproject.appspot.com/myhandler" } }
Response:
200 OK
{ "name": "projects/myproject/subscriptions/mysubscription", "topic": "projects/someproject/topics/sometopic", "pushConfig": { "pushEndpoint": "https://myproject.appspot.com/myhandler" }, "ackDeadlineSeconds": 10 }
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
The following samples demonstrate how to create a subscription with push delivery. By default, subscriptions use pull delivery.
C++
Before trying this sample, follow the C++ setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
Using subscription properties
You can set subscription properties when you create or update a subscription.
For more information about setting subscription properties with gcloud
command-line tool,
see the gcloud pubsub subscriptions create
or gcloud pubsub subscriptions update
optional flags.
Subscriptions have the following properties:
Property | Description | Default |
---|---|---|
Delivery method |
You can receive messages with pull or push delivery. In pull delivery, your subscriber application initiates requests to the Pub/Sub server to retrieve messages. In push delivery, Pub/Sub initiates requests to your subscriber application to deliver messages. |
If unspecified, Pub/Sub subscriptions use pull delivery. |
Acknowledgement deadline |
If your code doesn't acknowledge the message before the deadline, the message is sent again. |
10 seconds is the default acknowledgement deadline. The maximum is 10 minutes. |
Message retention duration |
The message retention duration specifies how long Pub/Sub retains messages after publication. After the message retention duration Pub/Sub might discard the message, regardless of its acknowledgement state. To retain acknowledged messages for the message retention duration, see Replaying and discarding messages. |
7 days is the default message retention duration. The minimum is 10 minutes and the maximum is 7 days. |
dead-letter topics |
If a subscriber can't acknowledge a message, Pub/Sub can forward the message to a dead-letter topic. For more information, see Forwarding to dead-letter topics. If you set a dead-letter topic, you can't enable message ordering. |
If you set a dead-letter topic, you can also specify the maximum number of delivery attempts. The default is 5 delivery attempts; you can specify 5-100 delivery attempts. If you set a dead-letter topic and the topic is in a different project than the subscription, you must also specify the project ID with the dead-letter topic. |
Expiration period |
Subscriptions without subscriber activity (such as open connections, active pulls, or successful pushes) expire. If Pub/Sub detects subscriber activity, the subscription deletion clock restarts. |
31 days is the default expiration period. The minimum is 1 day. To prevent a subscription from expiring, set the expiration period to |
Retry policy |
If the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement, Pub/Sub can send the message again using exponential backoff. |
If the retry policy isn't set, Pub/Sub resends the message as soon as the acknowledgement deadline expires or a subscriber responds with a negative acknowledgement. If the maximum backoff duration is set, the default minimum backoff duration is 10 seconds. If the minimum backoff duration is set, the default maximum backoff duration is 600 seconds. The longest backoff duration that you can specify is 600 seconds. |
Message ordering |
If publishers send messages with an ordering key and message ordering is set, Pub/Sub delivers the messages in order. |
If not set, Pub/Sub doesn't deliver messages in order, including messages with ordering keys. |
Filter |
The filter is a string with a filtering expression. If a subscription has a filter, the subscription only delivers the messages that match the filter. You can filter messages by their attributes. |
If unspecified, the subscription doesn't filter messages and subscribers receive all of the messages. |
Using retry policies
When a subscription has a retry policy, Pub/Sub resends unacknowledged messages after the backoff duration that you specify. Pub/Sub resends the messages after the backoff duration on a best-effort basis, so you might receive messages before the minimum backoff duration.
If messages are in a batch, Pub/Sub starts the exponential backoff when one of the following occurs:
- The subscriber sends a negative acknowledgement for every message in the batch.
- The acknowledgement deadline expires.
After the backoff duration, Pub/Sub redelivers the batch.
If you receive messages from a push subscription, Pub/Sub might redeliver messages after the push backoff instead of the exponential backoff duration. When the push backoff is longer than the exponential backoff duration, Pub/Sub redelivers unacknowledged messages after the push backoff.
Modifying delivery methods
You can switch between push and pull subscriptions with the
Cloud Console, gcloud
command-line tool, or the Pub/Sub API.
Console
To modify a push subscription, complete the following steps.
- In the Cloud Console, go to the Subscriptions page.
- Clickmore_vertnext to the subscription to update.
- In the Delivery Type, choose Pull or Push.
- Click Update.
gcloud
To modify the push endpoint URL, run the modify-push-config
command:
gcloud pubsub subscriptions modify-push-config SUBSCRIPTION_ID \ --push-endpoint=PUSH_ENDPOINT
If the subscription is already using pull delivery, setting the push endpoint switches the delivery method to push delivery.
You can switch from push to pull delivery by changing the push endpoint to an empty string.
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
Listing subscriptions
You can list the subscriptions in a Google Cloud project with the
Cloud Console, gcloud
command-line tool, or Pub/Sub API.
Console
To list the subscriptions in a project, go to the Subscriptions page.
gcloud
To list the subscriptions in a Google Cloud project, run the
gcloud pubsub subscriptions list
command:
gcloud pubsub subscriptions list [--project=PROJECT_ID]
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
You can list the subscriptions to a topic with the Cloud Console,
gcloud
command-line tool, or Pub/Sub API.
Console
- In the Cloud Console, go to the Topics page.
- Select a topic ID to open the Topic details page. The Subscriptions section of the page includes of list of subscriptions to the topic.
gcloud
To list the subscriptions in a Google Cloud project, run the
gcloud pubsub topics list-subscriptions
command:
gcloud pubsub topics list-subscriptions TOPIC_ID
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
Deleting subscriptions
You can delete subscriptions with the Cloud Console,
gcloud
command-line tool, or Pub/Sub API.
Console
- In the Cloud Console, go to the Subscriptions page.
- Select the subscription to delete.
- Click Delete.
gcloud
To delete a subscription, run the
gcloud pubsub subscriptions delete
command:
gcloud pubsub subscriptions delete SUBSCRIPTION_ID
C++
Before trying this sample, follow the C++ setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C++ API reference documentation.
C#
Before trying this sample, follow the C# setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
Before trying this sample, follow the Go setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Go API reference documentation.
Java
Before trying this sample, follow the Java setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Java API reference documentation.
Node.js
Before trying this sample, follow the Node.js setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
PHP
Before trying this sample, follow the PHP setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub PHP API reference documentation.
Python
Before trying this sample, follow the Python setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
Before trying this sample, follow the Ruby setup instructions in the Pub/Sub Quickstart Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
Resource names
A Pub/Sub resource name uniquely identifies a Pub/Sub resource, such as a subscription or topic, and must fit the following format:
projects/project-identifier/collection/relative-name
The project-identifier must be the project ID, available from the
Google Cloud Console. For example, projects/myproject/topics/mytopic
.
The collection must be one of subscriptions
or topics
.
The relative-name must:
- Not begin with the string
goog
. - Start with a letter
- Contain between 3 and 255 characters
Contain only the following characters:
- Letters:
[A-Za-z]
- Numbers:
[0-9]
- Dashes:
-
- Underscores:
_
- Periods:
.
- Tildes:
~
- Plus signs:
+
Percent signs:
%
The special characters in the above list can be used in resource names without URL-encoding. However, you must ensure that any other special characters are properly encoded/decoded when used in URLs. For example,
mi-tópico
is an invalid relative-name. However,mi-t%C3%B3pico
is valid.This is particularly important for REST calls.
- Letters: