Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Dokument wird beschrieben, wie Sie eine Single Message Transform (SMT) für ein Pub/Sub-Thema aktualisieren. Änderungen an SMTs werden innerhalb weniger Minuten wirksam. Bei SMTs für Themen gelten die Änderungen für neue Nachrichten, die nach der Aktualisierung der SMT veröffentlicht werden.
Sie können die SMTs für Themen über die Google Cloud Console, die Google Cloud CLI, die Clientbibliothek oder die Pub/Sub API aktualisieren.
Erforderliche Rollen und Berechtigungen
Bitten Sie Ihren Administrator, Ihnen die IAM-Rolle Pub/Sub-Bearbeiter (roles/pubsub.editor) für Ihr Projekt zuzuweisen, damit Sie die Berechtigungen erhalten, die Sie zum Aktualisieren von SMTs für Themen benötigen.
Weitere Informationen zum Zuweisen von Rollen finden Sie unter Zugriff auf Projekte, Ordner und Organisationen verwalten.
Diese vordefinierte Rolle enthält die Berechtigungen, die zum Aktualisieren von SMTs für Themen erforderlich sind. Erweitern Sie den Abschnitt Erforderliche Berechtigungen, um die erforderlichen Berechtigungen anzuzeigen:
Erforderliche Berechtigungen
Die folgenden Berechtigungen sind zum Aktualisieren von SMTs für Themen erforderlich:
Gewähren Sie der Aktualisierung die Berechtigung zum Aktualisieren eines Themas für das Thema:
projects.topics.patch
Erteilen Sie die Berechtigung „Thema ansehen“ für das Projekt. Diese Berechtigung ist nur erforderlich, wenn Sie die Google Cloud Console verwenden:
pubsub.topics.view
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.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-17 (UTC)."],[],[],null,["# Update topic SMTs\n\nThis document explains how to update a Single Message Transform (SMT) for a\nPub/Sub topic. Changes to SMTs take effect within a few minutes. For\ntopic SMTs, the changes apply to new messages published after the SMT is updated.\n\nTo update topic SMTs, you can use the Google Cloud console, the Google Cloud CLI,\nthe client library, or the Pub/Sub API.\n\nRequired roles and permissions\n------------------------------\n\n\nTo get the permissions that\nyou need to update topic SMTs,\n\nask your administrator to grant you the\n\n\n[Pub/Sub Editor](/iam/docs/roles-permissions/pubsub#pubsub.editor) (`roles/pubsub.editor`)\nIAM role on your project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains\n\nthe permissions required to update topic SMTs. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to update topic SMTs:\n\n- Grant the update a topic permission on the topic: ` ``projects.topics.patch`\n- Grant the view a topic permission on the project. This permission is only required if you are using the Google Cloud console: ` ``pubsub.topics.view`\n\n\nYou might also be able to get\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nYou can configure access control at the project level and at the individual\nresource level.\n\nUpdate topic SMTs\n-----------------\n\nTo update topic SMTs, follow these steps: \n\n### Console\n\n1. In the Google Cloud console, go to the Pub/Sub **Topics** page.\n\n [Go to Topics](https://console.cloud.google.com/cloudpubsub/topic)\n2. Click the topic for which you want to edit SMTs.\n\n3. In the topic details page, click **Edit**.\n\n The **Transforms** tab lists all the SMTs that are attached to the topic.\n4. In the Edit topic page, you can do the following tasks:\n\n 1. Add a new SMT. Click **Add a transform**.\n\n 2. Edit an existing SMT. Expand any SMT to edit the SMT.\n\n 3. Rearrange the SMTs. Use the up and down arrows.\n\n 4. Delete an SMT. Click the delete button.\n\n5. Click **Update**.\n\n### gcloud\n\n1. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/how-cloud-shell-works)\n session starts and displays a command-line prompt. Cloud Shell is a shell environment\n with the Google Cloud CLI\n already installed and with values already set for\n your current project. It can take a few seconds for the session to initialize.\n2. Run the\n [`gcloud pubsub topics update`](/sdk/gcloud/reference/pubsub/topics/update)command:\n\n \u003cbr /\u003e\n\n ```bash\n gcloud pubsub topics update TOPIC_ID \\\n --message-transforms-file=TRANSFORMS_FILE\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eTOPIC_ID\u003c/var\u003e: The ID or name of the topic you want to update.\n\n -\n \u003cvar translate=\"no\"\u003eTRANSFORMS_FILE\u003c/var\u003e: The path to the YAML or JSON file containing the\n updated SMTs.\n\n The following is an example of a YAML transforms file: \n\n ```yaml\n - javascriptUdf:\n code: \u003e\n function redactSSN(message, metadata) {\n const data = JSON.parse(message.data);\n delete data['ssn'];\n message.data = JSON.stringify(data);\n return message;\n }\n functionName: redactSSN\n - javascriptUdf:\n code: \u003e\n function filterHighAmount(message, metadata) {\n const data = JSON.parse(message.data);\n if (data['amount'] \u003e 100 ) { return null; }\n return message;\n }\n functionName: filterHighAmount\n ```\n\n \u003cbr /\u003e\n\n To clear all the SMTs from the topic, use the following command: \n\n ```bash\n gcloud pubsub topics update TOPIC_ID --clear-message-transforms\n ```\n\n Replace \u003cvar translate=\"no\"\u003eTOPIC_ID\u003c/var\u003e with the ID or name of the topic you want to update.\n\n \u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Create a topic with SMTs](/pubsub/docs/smts/create-topic-smt)\n\n- [Delete topic SMTs](/pubsub/docs/smts/delete-topic-smt)"]]