Storage Transfer Service 会在您添加通知配置后就任何启动的 TransferOperations 发送通知,并保证至少向 Pub/Sub 递送一次。Pub/Sub 也会向收件人至少送达一次通知,这意味着,您可能会收到多条消息,这些消息具有多个 ID,但它们均代表同一 Storage Transfer Service 事件。
我们不保证按照 Pub/Sub 接收通知的顺序发布通知。
如果通知始终无法送达 Pub/Sub 主题,Storage Transfer Service 可能会在 7 天后删除通知。当 Pub/Sub 主题不再存在时,Storage Transfer Service 不再具有向主题发布通知的权限时,或者拥有该主题的项目超出发布配额时,通知可能会递送失败。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# Pub/Sub notifications\n\nAfter you complete a Storage Transfer Service transfer, you might want to start another\ntask, handle an error encountered during a transfer, or log that a transfer\noccurred. Pub/Sub provides a queue that your programs subscribe to\nto receive messages when a transfer completes. This enables you to reuse code\nand to program next steps based on the state of a transfer.\n\nFor more information about Pub/Sub, see [What is Cloud\nPub/Sub](/pubsub/docs/overview)\n\nPrerequisites\n-------------\n\nBefore you can use this feature, do the following:\n\n1. [Enable the Pub/Sub API](/service-usage/docs/enable-disable)\n for the project receiving Pub/Sub notifications.\n\n [Enable\n the API](https://console.cloud.google.com/flows/enableapi?apiid=pubsub)\n2. [Have an existing Pub/Sub topic](/pubsub/docs/create-topic-console#create_a_topic)\n that you want to send notifications to.\n\n3. [Get the email address of the service account](/storage-transfer/docs/reference/rest/v1/googleServiceAccounts)\n associated with the project that contains your Storage Transfer Service\n bucket.\n\n 1. [Grant the service account the IAM role `roles.pubsub.publisher`](/pubsub/docs/access-control#console) for the desired Pub/Sub topic.\n\n | **Note:** There might be a delay of several seconds between assigning the role and having it applied to your service account. If you grant this permission programmatically, wait 30 seconds before configuring Storage Transfer Service.\n\nConfiguring notification settings\n---------------------------------\n\nTo configure Storage Transfer Service Pub/Sub notification settings,\nyou use the\n[Storage Transfer Service transferJobs API](/storage-transfer/docs/reference/rest/v1/transferJobs), to\ncreate `NotificationConfig` message. The topic will receive notifications on the\nconfigured Pub/Sub channel.\n\nSpecify the following in your `NotificationConfig` message:\n\n- The Pub/Sub topic to send notifications to\n- The format of the message, `\"JSON\"` or `\"NONE\"`\n- The desired event types, corresponding to completed\n [`TransferOperation.Statuses`](/storage-transfer/docs/reference/rest/v1/transferOperations#status):\n\n - `\"TRANSFER_OPERATION_SUCCESS\"`\n - `\"TRANSFER_OPERATION_FAILED\"`\n - `\"TRANSFER_OPERATION_ABORTED\"`\n\nThe following is an example `NotificationConfig` message: \n\n {\n ...\n \"notificationConfig\": {\n \"pubsubTopic\": \"projects/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/topics/\u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e\",\n \"eventTypes\": [\"TRANSFER_OPERATION_SUCCESS\"],\n \"payloadFormat\": \"JSON\"\n },\n ...\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e: The Google Cloud project ID of the transfer\n- \u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e: The Pub/Sub topic name\n\nFor more information, see [Storage Transfer Service Pub Sub REST specification](/storage-transfer/docs/reference/rest/v1/NotificationConfig).\n\nNotification format\n-------------------\n\nNotifications sent to the Pub/Sub topic consist of two parts:\n\n- **Attributes**: A set of key:value pairs describing the event.\n- **Payload**: A string that contains the metadata of the changed object.\n\n### Attributes\n\nAttributes are key:value pairs contained in all notifications sent by\nStorage Transfer Service to your Pub/Sub topic. Notifications always\ncontain the following set of key:value pairs, regardless of the notification's\npayload:\n\nSee [`PubsubMessage`](/pubsub/docs/reference/rest/v1/PubsubMessage) for more\ninformation about the Pub/Sub message format.\n\n### Payload\n\nThe payload contains the `TransferOperation` metadata. When you create a\nnotification configuration, you specify a type of payload to include in\nnotifications triggered by that configuration. You can specify the following\ntypes of payload:\n\nExample Pub/Sub notification configurations\n-------------------------------------------\n\n### Notifying for failed transfers only\n\nTo receive messages for failed transfers only, submit a `TransferJob` with a\n`NotificationConfig` that filters for failed transfers only: \n\n // REST JSON format:\n // https://cloud.google.com/storage-transfer/docs/create-manage-transfer-program\n {\n ...\n \"notificationConfig\": {\n \"pubsubTopic\": \"projects/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/topics/\u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e\",\n \"eventTypes\": [\"TRANSFER_OPERATION_FAILED\"],\n \"payloadFormat: \"JSON\"\n },\n ...\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e: The Google Cloud project ID of the transfer\n- \u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e: The Pub/Sub topic name\n\n### Notify on all completed transfers\n\nTo notify on all completed transfers, regardless of status, submit a\n`TransferJob` with a `NotificationConfig` without `EventType` filters: \n\n // REST JSON format:\n // https://cloud.google.com/storage-transfer/docs/create-manage-transfer-program\n {\n ...\n \"notificationConfig\": {\n \"pubsubTopic\": \"projects/\u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e/topics/\u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e\",\n \"payloadFormat: \"JSON\"\n },\n ...\n }\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eproject-id\u003c/var\u003e: The Google Cloud project ID of the transfer\n- \u003cvar translate=\"no\"\u003etopic-id\u003c/var\u003e: The Pub/Sub topic name\n\n### Performing arbitrary actions on a transfer\n\nTo perform an arbitrary action, you create a Pub/Sub notification\nusing a\n[Cloud function with a Pub/Sub trigger](/functions/docs/calling/pubsub)\npaired with a [background cloud function](/functions/docs/writing/background).\nFor more information, see the\n[Cloud Pub/Sub tutorial](/functions/docs/tutorials/pubsub).\n\nExamples of arbitrary actions include:\n\n- [Sending an email](/compute/docs/tutorials/sending-mail)\n- [Starting a Dataflow job](/dataflow/docs/quickstarts/create-pipeline-python)\n- [Recording metadata in Cloud SQL](/sql/docs/mysql/connect-functions)\n- [Recording metadata in Spanner](/spanner/docs/reference/libraries)\n\nDelivery guarantees\n-------------------\n\n| **Important:** There is currently no SLA for delivery time, but notifications are typically delivered within seconds. In some circumstances notifications might be delayed substantially longer.\n\nStorage Transfer Service sends notifications for any `TransferOperations` started\nafter you add a notification configuration, and guarantees at-least-once\ndelivery to Pub/Sub. Pub/Sub also offers\nat-least-once delivery to the recipient, which means that you could receive\nmultiple messages, with multiple IDs, that represent the same\nStorage Transfer Service event.\n\nNotifications are not guaranteed to be published in the order\nPub/Sub receives them.\n\nIf a notification consistently cannot be delivered to a Pub/Sub\ntopic, Storage Transfer Service might delete the notification after 7 days. Delivery\nfailure can occur when the Pub/Sub topic no longer exists, when\nStorage Transfer Service no longer has permission to publish to the topic, or when\nthe project that owns the topic exceeds its publishing quota."]]