After you create a subscription, you can change the delivery method to push, pull, or export.
Before you begin
- Create one of the supported subscriptions.
Required roles and permissions
To get the permission that
you need to change a subscription type,
ask your administrator to grant you the
Pub/Sub Editor (roles/pubsub.editor)
IAM role on the subscription.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
permission,
which is required to
change a subscription type.
pubsub.subscriptions.update
You might also be able to get this permission with custom roles or other predefined roles.
You can configure access control at the project level and at the individual resource level. You can create a subscription in one project and attach it to a topic located in a different project. Ensure that you have the required permissions for each project.
Change the delivery type of a subscription
To change a subscription's delivery type, perform the following steps.
Console
In the Google Cloud console, go to the Subscriptions page.
Click the name of the subscription that you want to update.
In the subscription details page, click Edit.
For Delivery type, select the new delivery type.
Fill in the properties for the new subscription type. For more information, see the following topics:
Optional. Update other subscription properties as required.
Click Update.
gcloud
To change the delivery type, use the
gcloud pubsub subscriptions update
command. Clear the configuration for the current delivery type and set the
configuration for the new type, as follows:
gcloud pubsub subscriptions update SUBSCRIPTION_ID \
CLEAR_CONFIG_FLAG \
NEW_CONFIG_FLAGS
Replace the following:
SUBSCRIPTION_ID: The name of the subscription to update.
CLEAR_CONFIG_FLAG: A flag to clear the existing configuration for the delivery type. Use one of the following flags, depending on the current delivery type:
Pull subscription:
--no-enable-exactly-once-deliveryPush subscription:
--push-endpoint=""BigQuery subscription:
--clear-bigquery-configCloud Storage subscription:
--clear-cloud-storage-config
NEW_CONFIG_FLAGS: Flags to configure the new delivery type. For more information, see the documentation for the
gcloud pubsub subscriptions updatecommand.
Examples
Change a BigQuery subscription to a pull subscription:
gcloud pubsub subscriptions update SUBSCRIPTION_ID \
--clear-bigquery-config
Change a push subscription to a BigQuery subscription:
gcloud pubsub subscriptions update SUBSCRIPTION_ID \
--push-endpoint="" \
--bigquery-table=BIGQUERY_TABLE
Update a push subscription endpoint
To update the endpoint URL on a push subscription, perform the following steps.
Console
To modify the endpoint URL, complete the following steps.
- In the Google Cloud console, go to the Subscriptions page.
- Click more_vert next to the subscription to update.
- In the Delivery type, choose a delivery option.
- Fill in other subscription properties as required.
- Click Update.
gcloud
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
To modify the endpoint URL, run the
gcloud pubsub subscriptions modify-push-configcommand: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.
REST
To modify the push configurations of a subscription, use the
projects.subscriptions.modifyPushConfig
method:
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.
POST https://pubsub.googleapis.com/v1/projects/PROJECT_ID/subscriptions/SUBSCRIPTION_ID:modifyPushConfig Authorization: Bearer ACCESS_TOKEN
Request body:
{
"pushConfig": {
"pushEndpoint": "PUSH_ENDPOINT"
}
}Where:
https://myproject.appspot.com/myhandler.Response:
If the request is successful, the response is an empty JSON object.
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 Quickstart: Using Client Libraries. For more information, see the Pub/Sub C# API reference documentation.
Go
The following sample uses the major version of the Go Pub/Sub client library (v2). If you are still using the v1 library, see the migration guide to v2. To see a list of v1 code samples, see the deprecated code samples.
Before trying this sample, follow the Go setup instructions in 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 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 Quickstart: Using Client Libraries. For more information, see the Pub/Sub Node.js API reference documentation.
Node.ts
Before trying this sample, follow the Node.js setup instructions in 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 Quickstart: Using Client Libraries. For more information, see the Pub/Sub Python API reference documentation.
Ruby
The following sample uses Ruby Pub/Sub client library v3. If you are still using the v2 library, see the migration guide to v3. To see a list of Ruby v2 code samples, see the deprecated code samples.
Before trying this sample, follow the Ruby setup instructions in Quickstart: Using Client Libraries. For more information, see the Pub/Sub Ruby API reference documentation.
What's next
- Create or modify a subscription with
gcloudcommands. - Create or modify a subscription with REST APIs.