[[["易于理解","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-02。"],[[["\u003cp\u003eArtifact Registry sends notifications about changes to Docker repositories, including image uploads, new tags, and image deletions, through Pub/Sub messages.\u003c/p\u003e\n"],["\u003cp\u003eTo receive these notifications, you must create a Pub/Sub topic named \u003ccode\u003egcr\u003c/code\u003e and set up a subscription to that topic within your project.\u003c/p\u003e\n"],["\u003cp\u003eSubscriber applications can be configured to receive messages via pull delivery, which is recommended for CI/CD systems that generate frequent changes.\u003c/p\u003e\n"],["\u003cp\u003eThe Artifact Registry service account publishes changes to the \u003ccode\u003egcr\u003c/code\u003e topic, or if permissions are revoked, it defaults to publishing as the user who made the change, meaning the user's account needs the \u003ccode\u003epubsub.topics.publish\u003c/code\u003e permission.\u003c/p\u003e\n"],["\u003cp\u003ePub/Sub messages are sent in JSON format, containing information about the \u003ccode\u003eaction\u003c/code\u003e (INSERT or DELETE) along with the relevant \u003ccode\u003edigest\u003c/code\u003e or \u003ccode\u003etag\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Configuring Pub/Sub notifications\n\nYou can receive notifications from [Pub/Sub](/pubsub) for the\nchanges to a Docker repository. Notifications apply to any container image\nstored in the repository, including [Helm 3 charts](/artifact-registry/docs/helm)\npackaged in OCI format.\n\nPub/Sub publishes messages about your repositories to named\nresources called *topics* . Applications that *subscribe* to Pub/Sub\ntopics receive these messages and receive notifications when a repository's\nstate changes.\n\nArtifact Registry publishes messages for the following changes:\n\n- Image uploads\n- New tags added to images\n- Image deletion\n\nAdditionally, you can configure roles and permissions for publishing or\nsubscribing to notifications.\nFor information about configuring Artifact Analysis notifications for activity such as new vulnerability scan results, see the [Artifact Analysis documentation](/artifact-analysis/docs/pub-sub-notifications).\n\nOverview\n--------\n\nArtifact Registry publishes messages about changes to repositories in a\ntopic named `gcr`.\n\nTo receive notifications, you must:\n\n1. [Create a topic](#topic) named `gcr` in the project with Artifact Registry.\n2. [Create a subscription](#subscription) to the topic.\n3. Set up your [subscriber application](#subscriber) to receive messages about repository changes.\n4. If appropriate, [configure permissions](#permissions) to control access to your topic and subscription.\n\nCreating the Artifact Registry topic\n------------------------------------\n\nTo create the `gcr` topic with Google-owned and Google-managed encryption keys: \n\n### Console\n\n1. Go to the Pub/Sub topics page in the Google Cloud console.\n\n [Go to the Pub/Sub topics page](https://console.cloud.google.com/cloudpubsub/topicList)\n2. Click **Create Topic**.\n\n3. Enter the topic ID `gcr`.\n\n4. Click **Create Topic**.\n\n### gcloud\n\nRun the following command: \n\n gcloud pubsub topics create gcr --project=\u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e\n\nReplace \u003cvar translate=\"no\"\u003ePROJECT-ID\u003c/var\u003e with your Google Cloud\n[project ID](/resource-manager/docs/creating-managing-projects#identifying_projects). If you omit the `--project` flag, the command\nuses the current project.\n| **Note:** If this command returns a \"Resource already exists in the project\" error, the topic `gcr` already exists in the project.\n\nTo learn more about the `gcloud pubsub topics` command, see the\n[`topics` documentation](/sdk/gcloud/reference/pubsub/topics).\n\nTo create the `gcr` topic with CMEK encryption, see the Pub/Sub\n[instructions for encrypting topics](/pubsub/docs/encryption#using-cmek).\n\nAfter you have have created the `gcr` topic or verified that it exists, you can\ncreate a [subscription](#subscription) to the topic.\n\nCreating a subscription\n-----------------------\n\nAfter you have [created a topic](#topic) for repository changes, you can\nconfigure a subscription to it that uses either [push delivery](/pubsub/docs/push)\nor [pull delivery](/pubsub/docs/pull). We recommend using pull delivery since\nCI/CD systems can generate numerous changes to stored artifacts, and pull\ndelivery is more effective for a large volume of messages.\n\nTo create a subscription with pull delivery: \n\n### Console\n\n1. Go to the Pub/Sub topics page in the Google Cloud console.\n\n [Go to the Pub/Sub topics page](https://console.cloud.google.com/cloudpubsub/topicList)\n2. Click your project's topic.\n\n3. Click **Create Subscription**.\n\n4. Enter a subscription name:\n\n projects/\u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e/subscriptions/[SUBSCRIPTION-NAME]\n\n Leave **Delivery Type** set to **Pull**.\n5. Click **Create**.\n\n### gcloud\n\nRun the following command: \n\n gcloud pubsub subscriptions create \u003cvar translate=\"no\"\u003eSUBSCRIPTION-NAME\u003c/var\u003e --topic=gcr\n\nReplace \u003cvar translate=\"no\"\u003eSUBSCRIPTION-NAME\u003c/var\u003e with a name for the subscription\n| **Note:** Use the optional flag `--ack-deadline` to configure how many seconds the system will wait for acknowledgement from the subscriber before re-attempting delivery. Without this flag, the default deadline is 10 seconds.\n\nTo learn more about the `gcloud pubsub subscriptions` command, see the\n[`subscriptions` documentation](/sdk/gcloud/reference/pubsub/subscriptions).\n\nYou now have a subscription to the `gcr` topic. The next step is\n[configuring permissions](#permissions) for the identities that trigger changes\nin repositories.\n\nConfiguring your subscriber application\n---------------------------------------\n\nAfter you have [created a topic](#topic) and a [subscription](#subscription)\nto that topic, you can set up your subscriber application, the application\nthat receive messages about changes to repositories. Subscriber applications\nfulfill tasks like event notifications, system logging,\nand communication between applications.\n\nWhen a repository user pushes or deletes an image, the following steps occur:\n\n1. The Artifact Registry service account publishes the change to your `gcr`\n topic. The service account is **service-\u003cvar translate=\"no\"\u003ePROJECT-NUMBER\u003c/var\u003e@gcp-sa-artifactregistry.iam.gserviceaccount.com** ,\n where \u003cvar translate=\"no\"\u003ePROJECT-NUMBER\u003c/var\u003e is your Google Cloud [project number](/resource-manager/docs/creating-managing-projects#identifying_projects). The\n Artifact Registry service account has the `pubsub.topics.publish`\n permission by default so that it can publish changes to your topic.\n\n If an administrator has revoked the `pubsub.topics.publish` permissions for\n the Artifact Registry service account, Artifact Registry attempts to publish\n the message as the repository user. In this situation, the repository user's\n account must have the `pubsub.topics.publish` permission to successfully\n publish the message.\n2. Pub/Sub forwards the message from the topic to your subscription.\n\n3. When your subscriber application makes a request for messages, it pulls\n the new message from the subscription.\n\n The identity that pulls messages on behalf of the subscriber must have\n permissions to access the subscription. You can use the\n [Pub/Sub Subscriber role](/pubsub/docs/access-control#roles)\n to grant this permission.\n\nTo learn about setting up a subscriber to receive messages from a subscription\nwith pull delivery, see [Receiving messages using Pull](/pubsub/docs/pull).\n\nConfiguring permissions\n-----------------------\n\nYou can use Pub/Sub permissions to control access to your topics and\nsubscriptions.\n\nFor more information about Pub/Sub permissions and granting access to\ntopics and subscriptions, see the Pub/Sub\n[access control documentation](/pubsub/docs/access-control).\n\nNotification examples\n---------------------\n\nPub/Sub sends notifications as JSON-formatted strings. Review the\nfollowing examples to learn what to expect when receiving Artifact Registry notifications from Pub/Sub.\n\nWhen an image is pushed to Artifact Registry, the notification\npayload might look like this: \n\n {\n \"action\":\"INSERT\",\n \"digest\":\"us-west1-docker.pkg.dev/my-project/my-repo/hello-world@sha256:6ec128e26cd5...\"\n }\n\nWhen a new image tag is pushed to Artifact Registry, the notification\npayload looks like this: \n\n {\n \"action\":\"INSERT\",\n \"digest\":\"us-west1-docker.pkg.dev/my-project/my-repo/hello-world@sha256:6ec128e26cd5...\",\n \"tag\":\"us-west1-docker.pkg.dev/my-project/my-repo/hello-world:1.1\"\n }\n\nThe message identifies the relevant image using either a `digest` or `tag` key.\n\nWhen an image tag is deleted from Artifact Registry, the notification\npayload might look like this: \n\n {\n \"action\":\"DELETE\",\n \"tag\":\"us-west1-docker.pkg.dev/my-project/my-repo/hello-world:1.1\"\n }\n\nThe message might contain either `DELETE` or `INSERT` as values for the `action`\nkey.\n\nWhat's next\n-----------\n\n- Read the [Pub/Sub documentation](/pubsub/docs).\n- For an in-depth explanation of Pub/Sub, see [What is Pub/Sub?](/pubsub/docs/overview)\n- Learn more about [Pub/Sub access control roles](/pubsub/docs/access_control#tbl_roles)."]]