Change subscription types

After you create a subscription, you can change the delivery method to push, pull, or export.

Before you begin

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 pubsub.subscriptions.update permission, which is required to change a subscription type.

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

  1. In the Google Cloud console, go to the Subscriptions page.

    Go to Subscriptions

  2. Click the name of the subscription that you want to update.

  3. In the subscription details page, click Edit.

  4. For Delivery type, select the new delivery type.

  5. Fill in the properties for the new subscription type. For more information, see the following topics:

  6. Optional. Update other subscription properties as required.

  7. 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-delivery

    • Push subscription: --push-endpoint=""

    • BigQuery subscription: --clear-bigquery-config

    • Bigtable subscription: --clear-bigtable-config

    • Cloud 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 update command.

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.

  1. In the Google Cloud console, go to the Subscriptions page.

    Go to Subscriptions

  2. Click next to the subscription to update.
  3. In the Delivery type, choose a delivery option.
  4. Fill in other subscription properties as required.
  5. Click Update.

gcloud

  1. In the Google Cloud console, activate Cloud Shell.

    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.

  2. To modify the endpoint URL, run the gcloud pubsub subscriptions 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.

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:

  • PROJECT_ID is your project ID.
  • SUBSCRIPTION_ID is your subscription ID.
  • PUSH_ENDPOINT is a modified URL that you want to apply as your new push endpoint. For example, 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.

    namespace pubsub_admin = ::google::cloud::pubsub_admin;
    namespace pubsub = ::google::cloud::pubsub;
    [](pubsub_admin::SubscriptionAdminClient client,
       std::string const& project_id, std::string const& subscription_id,
       std::string const& endpoint) {
      google::pubsub::v1::ModifyPushConfigRequest request;
      request.set_subscription(
          pubsub::Subscription(project_id, subscription_id).FullName());
      request.mutable_push_config()->set_push_endpoint(endpoint);
      auto status = client.ModifyPushConfig(request);
      if (!status.ok()) throw std::runtime_error(status.message());
    
      std::cout << "The subscription push configuration was successfully"
                << " modified\n";
    }

    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.

    
    using Google.Cloud.PubSub.V1;
    
    public class UpdatePushConfigurationSample
    {
        public void UpdatePushConfiguration(string projectId, string subscriptionId, string pushEndpoint)
        {
            SubscriberServiceApiClient subscriber = SubscriberServiceApiClient.Create();
            SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId);
    
            PushConfig pushConfig = new PushConfig { PushEndpoint = pushEndpoint