本文档介绍了如何从现有 Pub/Sub 订阅中删除单条消息转换 (SMT)。
如需删除订阅 SMT,您可以使用 Google Cloud 控制台、Google Cloud CLI、客户端库或 Pub/Sub API。
所需的角色和权限
如需获得删除订阅 SMT 所需的权限,请让您的管理员为您授予项目的 Pub/Sub Editor (roles/pubsub.editor
) IAM 角色。
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
此预定义角色包含删除订阅 SMT 所需的权限。如需查看所需的确切权限,请展开所需权限部分:
所需权限
如需删除订阅 SMT,您需要具备以下权限:
-
向订阅授予删除订阅权限:
pubsub.subscriptions.delete
-
向视图授予对项目的订阅权限。只有在使用 Google Cloud 控制台时,才需要此权限:
pubsub.subscriptions.view
您可以在项目级别和各个资源级别配置访问权限控制。
删除订阅 SMT
如需删除订阅 SMT,请按以下步骤操作:
控制台
-
在 Google Cloud 控制台中,前往 Pub/Sub 订阅 页面。
-
点击要为其删除 SMT 的订阅。
-
在订阅详情页面中,点击修改。
转换标签页会列出附加到订阅的所有 SMT。
-
点击要删除的 SMT 对应的删除按钮。
-
点击更新。
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.
-
此命令会删除与指定订阅关联的所有 SMT。
运行带有
--clear-message-transforms
标志的gcloud pubsub subscriptions update
命令:gcloud pubsub subscriptions update SUBSCRIPTION_ID \ --clear-message-transforms
替换以下内容:
-
SUBSCRIPTION_ID:要更新的订阅的 ID 或名称。
如需移除单个 SMT,请参阅更新订阅 SMT,然后创建一个新的
message-transforms-file
,其中不包含要删除的 SMT。 -