接收包含元数据更改 Feed 的通知

本文档介绍了如何配置 Knowledge Catalog(以前称为 Dataplex Universal Catalog)元数据更改 Feed,以便在 Knowledge Catalog 中的元数据被创建、更新或删除时通过 Pub/Sub 接收通知。

如需详细了解元数据更改 Feed,请参阅元数据更改 Feed 概览

准备工作

熟悉 Pub/SubDataplex API

  1. 启用 Dataplex API 和 Pub/Sub API。

    启用 API 所需的角色

    如需启用 API,您需要拥有 serviceusage.services.enable 权限。如果您创建了项目,则可能已经通过 Owner 角色 (roles/owner) 获得了此权限。否则,您可以通过 Service Usage Admin 角色 (roles/serviceusage.serviceUsageAdmin) 获得此权限。了解如何授予角色

    启用 API

  2. 创建 Pub/Sub 主题以接收通知。如需了解详情,请参阅创建主题

  3. 安装 gcloud。 确保已设置 gcloud 的简短别名。

  4. 设置 gcurl 的别名。这会创建一个包含您的身份验证令牌的快捷方式,并为 API 请求设置 JSON 内容类型:

    alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
    
  5. 设置 DATAPLEX_API 变量:

    DATAPLEX_API="dataplex.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION"
    

    替换以下内容:

    • PROJECT_ID:已启用 Dataplex API 的项目 ID
    • LOCATION:作业的运行位置,例如 us-central1europe-west3asia-south1

所需的角色和权限

如需配置元数据更改 Feed,请确保您和 Knowledge Catalog 服务账号拥有所需的 IAM 角色和权限。

用户角色和权限

如需获得导出元数据和访问元数据更改 Feed 消息所需的权限,请让您的管理员为您授予项目或组织的以下 IAM 角色:

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

这些预定义角色可提供导出元数据和访问元数据更改 Feed 消息所需的权限。如需查看所需的确切权限,请展开所需权限部分:

所需权限

如需导出元数据和访问元数据更改 Feed 消息,您需要具备以下权限:

  • 导出元数据:
    • 针对项目的 dataplex.metadataFeeds.create 权限
    • 针对定义 Feed 范围的资源(组织、项目或条目组)的 dataplex.entryGroups.export
    • 针对项目的 resourcemanager.projects.get 权限
    • 针对项目的 resourcemanager.projects.list 权限
  • 访问元数据更改 Feed 消息:
    • 针对订阅的 pubsub.subscriptions.consume
    • 针对主题的 pubsub.topics.attachSubscription 权限

您也可以使用自定义角色或其他预定义角色来获取这些权限。

Knowledge Catalog 服务账号角色和权限

为了确保知识目录服务账号拥有发布元数据更改 Feed 消息所需的权限,请让您的管理员向 Pub/Sub 主题中的知识目录服务账号授予 Pub/Sub Publisher (roles/pubsub.publisher) 和 Pub/Sub Viewer (roles/pubsub.viewer) IAM 角色。

如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限

此预定义角色包含发布元数据更改 Feed 消息所需的 pubsub.topics.publishpubsub.topics.get 权限。

您的管理员也可以使用自定义角色或其他预定义角色为 Knowledge Catalog 服务账号授予此权限。

向知识目录服务账号授予权限

启用 Dataplex API 后,系统会在 Knowledge Catalog 中创建服务代理。您可以通过服务代理的电子邮件 ID 来识别它:

service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com

其中,PROJECT_NUMBER 是您已在其中启用 Dataplex API 的项目的项目编号。

Knowledge Catalog 服务账号需要能够向您的 Pub/Sub 主题发布消息并检索主题元数据。 如需授予这些权限,请向服务账号授予 Pub/Sub 主题的 Pub/Sub 发布者角色 (roles/pubsub.publisher) 和 Pub/Sub 查看者角色 (roles/pubsub.viewer):

gcloud

运行 gcloud pubsub topics add-iam-policy-binding 命令:

gcloud pubsub topics add-iam-policy-binding TOPIC_ID \
    --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
    --role="roles/pubsub.publisher"

gcloud pubsub topics add-iam-policy-binding TOPIC_ID \
    --member="serviceAccount:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com" \
    --role="roles/pubsub.viewer"

替换以下内容:

  • TOPIC_ID:您的 Pub/Sub 主题的 ID,元数据更改 Feed 消息会发布到该主题。
  • PROJECT_NUMBER:Knowledge Catalog 项目的项目编号,服务账号位于该项目中。

控制台

  1. 在 Google Cloud 控制台中,前往 Pub/Sub 主题页面。

    前往“主题”页面

  2. 选择您用于元数据 Feed 通知的主题,然后根据需要点击显示信息面板

  3. 权限标签页中,点击添加主账号

  4. 新的主账号字段中,输入 Knowledge Catalog 服务账号:service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com

  5. 分配角色字段中,选择 Pub/Sub 发布者

  6. 点击添加其他角色,然后选择 Pub/Sub Viewer

  7. 点击保存

创建元数据变更 Feed

如需控制哪些更改会生成通知,您可以配置元数据变更 Feed 来监控特定资源。为此,您需要指定范围,例如整个组织、特定项目或特定条目组。 虽然范围可让您定义要监控哪些资源,但您可以使用过滤条件进一步细化 Knowledge Catalog 发送通知的时间

如需了解详情,请参阅元数据更改 Feed

C#

C#

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 C# 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog C# API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dataplex.V1;
using Google.LongRunning;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for CreateMetadataFeed</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void CreateMetadataFeedRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        CreateMetadataFeedRequest request = new CreateMetadataFeedRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            MetadataFeed = new MetadataFeed(),
            MetadataFeedId = "",
            ValidateOnly = false,
        };
        // Make the request
        Operation<MetadataFeed, OperationMetadata> response = catalogServiceClient.CreateMetadataFeed(request);

        // Poll until the returned long-running operation is complete
        Operation<MetadataFeed, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        MetadataFeed result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<MetadataFeed, OperationMetadata> retrievedResponse = catalogServiceClient.PollOnceCreateMetadataFeed(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            MetadataFeed retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Go API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


//go:build examples

package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.CreateMetadataFeedRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#CreateMetadataFeedRequest.
	}
	op, err := c.CreateMetadataFeed(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Java API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.CreateMetadataFeedRequest;
import com.google.cloud.dataplex.v1.LocationName;
import com.google.cloud.dataplex.v1.MetadataFeed;

public class SyncCreateMetadataFeed {

  public static void main(String[] args) throws Exception {
    syncCreateMetadataFeed();
  }

  public static void syncCreateMetadataFeed() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      CreateMetadataFeedRequest request =
          CreateMetadataFeedRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setMetadataFeed(MetadataFeed.newBuilder().build())
              .setMetadataFeedId("metadataFeedId1633421160")
              .setValidateOnly(true)
              .build();
      MetadataFeed response = catalogServiceClient.createMetadataFeedAsync(request).get();
    }
  }
}

Node.js

Node.js

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Node.js API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the parent location, in the format
 *  `projects/{project_id_or_number}/locations/{location_id}`
 */
// const parent = 'abc123'
/**
 *  Required. The metadata job resource.
 */
// const metadataFeed = {}
/**
 *  Optional. The metadata job ID. If not provided, a unique ID is generated
 *  with the prefix `metadata-job-`.
 */
// const metadataFeedId = 'abc123'
/**
 *  Optional. The service validates the request without performing any
 *  mutations. The default is false.
 */
// const validateOnly = true

// Imports the Dataplex library
const {CatalogServiceClient} = require('@google-cloud/dataplex').v1;

// Instantiates a client
const dataplexClient = new CatalogServiceClient();

async function callCreateMetadataFeed() {
  // Construct request
  const request = {
    parent,
    metadataFeed,
  };

  // Run request
  const [operation] = await dataplexClient.createMetadataFeed(request);
  const [response] = await operation.promise();
  console.log(response);
}

callCreateMetadataFeed();

Python

Python

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Python 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Python API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_create_metadata_feed():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    metadata_feed = dataplex_v1.MetadataFeed()
    metadata_feed.pubsub_topic = "pubsub_topic_value"

    request = dataplex_v1.CreateMetadataFeedRequest(
        parent="parent_value",
        metadata_feed=metadata_feed,
    )

    # Make the request
    operation = client.create_metadata_feed(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

REST

如需创建元数据更改 Feed,请使用 projects.locations.metadataFeeds.create 方法。

组织范围

运行以下命令,创建用于监控整个组织的元数据更改 Feed:

gcurl -X POST -d "$(cat <<EOF
{
  "scope": {
    "organizationLevel": true
  },
  "pubsubTopic": "projects/PROJECT_ID_PUBSUB/topics/TOPIC_ID"
}
EOF
)" "https://${DATAPLEX_API}/metadataFeeds?metadataFeedId=FEED_ID"

替换以下内容:

  • PROJECT_ID_PUBSUB:Pub/Sub 主题所在的项目 ID,例如 example-project
  • TOPIC_ID:元数据更改 Feed 消息发布到的 Pub/Sub 主题 ID,例如 example-topic
  • FEED_ID:要创建的元数据更改 Feed ID,例如 example-feed

项目范围

运行以下命令,创建用于监控特定项目的元数据更改 Feed:

gcurl -X POST -d "$(cat <<EOF
{
  "scope": {
    "projects": [
      "projects/PROJECT_ID_1",
      "projects/PROJECT_ID_2"
    ]
  },
  "pubsubTopic": "projects/PROJECT_ID_PUBSUB/topics/TOPIC_ID"
}
EOF
)" "https://${DATAPLEX_API}/metadataFeeds?metadataFeedId=FEED_ID"

替换以下内容:

  • PROJECT_ID_PUBSUB:Pub/Sub 主题所在的项目 ID,例如 example-project
  • TOPIC_ID:元数据更改 Feed 消息发布到的 Pub/Sub 主题 ID,例如 example-topic
  • FEED_ID:要创建的元数据更改 Feed ID,例如 example-feed

条目组范围

运行以下命令,创建用于监控特定条目组的元数据更改 Feed:

gcurl -X POST -d "$(cat <<EOF
{
  "scope": {
    "entryGroups": [
      "projects/PROJECT_ID/locations/LOCATION/entryGroups/ENTRY_GROUP_ID_1",
      "projects/PROJECT_ID/locations/LOCATION/entryGroups/ENTRY_GROUP_ID_2"
    ]
  },
  "pubsubTopic": "projects/PROJECT_ID_PUBSUB/topics/TOPIC_ID"
}
EOF
)" "https://${DATAPLEX_API}/metadataFeeds?metadataFeedId=FEED_ID"

替换以下内容:

  • PROJECT_ID_PUBSUB:Pub/Sub 主题所在的项目 ID,例如 example-project
  • LOCATION:您要在其中创建 Feed 的位置,例如 us-central1
  • ENTRY_GROUP_ID:要监控的条目组 ID,例如 example-entry-group
  • TOPIC_ID:元数据更改 Feed 消息发布到的 Pub/Sub 主题 ID,例如 example-topic
  • FEED_ID:要创建的元数据更改 Feed ID,例如 example-feed

使用过滤条件

运行以下命令,创建包含过滤条件的元数据更改 Feed(按条目类型过滤):

gcurl -X POST -d "$(cat <<EOF
{
  "scope": {
    "projects": [
      "projects/PROJECT_ID_1",
      "projects/PROJECT_ID_2"
    ]
  },
  "filter": {
    "entryTypes": [
      "projects/PROJECT_ID/locations/global/entryTypes/bigquery-table"
    ]
  },
  "pubsubTopic": "projects/PROJECT_ID_PUBSUB/topics/TOPIC_ID"
}
EOF
)" "https://${DATAPLEX_API}/metadataFeeds?metadataFeedId=FEED_ID"

替换以下内容:

  • PROJECT_ID_PUBSUB:Pub/Sub 主题所在的项目 ID,例如 example-project
  • TOPIC_ID:元数据更改 Feed 消息发布到的 Pub/Sub 主题 ID,例如 example-topic
  • FEED_ID:要创建的元数据更改 Feed ID,例如 example-feed

回答:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.dataplex.v1.OperationMetadata",
    "createTime": "2023-10-02T15:01:23Z",
    "target": "projects/PROJECT_ID/locations/LOCATION/metadataFeeds/FEED_ID",
    "verb": "create",
    "apiVersion": "v1"
  },
  "done": false
}

查看元数据更改 Feed

您可以查看元数据更改 Feed 的详细信息。

C#

C#

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 C# 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog C# API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

using Google.Cloud.Dataplex.V1;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for GetMetadataFeed</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void GetMetadataFeedRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        GetMetadataFeedRequest request = new GetMetadataFeedRequest
        {
            MetadataFeedName = MetadataFeedName.FromProjectLocationMetadataFeed("[PROJECT]", "[LOCATION]", "[METADATA_FEED]"),
        };
        // Make the request
        MetadataFeed response = catalogServiceClient.GetMetadataFeed(request);
    }
}

Go

Go

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Go API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


//go:build examples

package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.GetMetadataFeedRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#GetMetadataFeedRequest.
	}
	resp, err := c.GetMetadataFeed(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Java API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.GetMetadataFeedRequest;
import com.google.cloud.dataplex.v1.MetadataFeed;
import com.google.cloud.dataplex.v1.MetadataFeedName;

public class SyncGetMetadataFeed {

  public static void main(String[] args) throws Exception {
    syncGetMetadataFeed();
  }

  public static void syncGetMetadataFeed() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      GetMetadataFeedRequest request =
          GetMetadataFeedRequest.newBuilder()
              .setName(MetadataFeedName.of("[PROJECT]", "[LOCATION]", "[METADATA_FEED]").toString())
              .build();
      MetadataFeed response = catalogServiceClient.getMetadataFeed(request);
    }
  }
}

Node.js

Node.js

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Node.js API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the metadata feed, in the format
 *  `projects/{project_id_or_number}/locations/{location_id}/MetadataFeeds/{metadata_feed_id}`.
 */
// const name = 'abc123'

// Imports the Dataplex library
const {CatalogServiceClient} = require('@google-cloud/dataplex').v1;

// Instantiates a client
const dataplexClient = new CatalogServiceClient();

async function callGetMetadataFeed() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const response = await dataplexClient.getMetadataFeed(request);
  console.log(response);
}

callGetMetadataFeed();

Python

Python

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Python 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Python API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_get_metadata_feed():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.GetMetadataFeedRequest(
        name="name_value",
    )

    # Make the request
    response = client.get_metadata_feed(request=request)

    # Handle the response
    print(response)

REST

如需查看元数据更改 Feed,请使用 projects.locations.metadataFeeds.get 方法。

运行以下命令:

gcurl "https://${DATAPLEX_API}/metadataFeeds/FEED_ID"

替换以下内容:

  • FEED_ID:您要查看的元数据更改 Feed ID,例如 example-feed

列出元数据更改 Feed

您可以列出项目和位置中的元数据更改 Feed。

C#

C#

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 C# 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog C# API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

using Google.Api.Gax;
using Google.Api.Gax.ResourceNames;
using Google.Cloud.Dataplex.V1;
using System;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for ListMetadataFeeds</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void ListMetadataFeedsRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        ListMetadataFeedsRequest request = new ListMetadataFeedsRequest
        {
            ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"),
            Filter = "",
            OrderBy = "",
        };
        // Make the request
        PagedEnumerable<ListMetadataFeedsResponse, MetadataFeed> response = catalogServiceClient.ListMetadataFeeds(request);

        // Iterate over all response items, lazily performing RPCs as required
        foreach (MetadataFeed item in response)
        {
            // Do something with each item
            Console.WriteLine(item);
        }

        // Or iterate over pages (of server-defined size), performing one RPC per page
        foreach (ListMetadataFeedsResponse page in response.AsRawResponses())
        {
            // Do something with each page of items
            Console.WriteLine("A page of results:");
            foreach (MetadataFeed item in page)
            {
                // Do something with each item
                Console.WriteLine(item);
            }
        }

        // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
        int pageSize = 10;
        Page<MetadataFeed> singlePage = response.ReadPage(pageSize);
        // Do something with the page of items
        Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
        foreach (MetadataFeed item in singlePage)
        {
            // Do something with each item
            Console.WriteLine(item);
        }
        // Store the pageToken, for when the next page is required.
        string nextPageToken = singlePage.NextPageToken;
    }
}

Go

Go

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Go API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


//go:build examples

package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
	"google.golang.org/api/iterator"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.ListMetadataFeedsRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#ListMetadataFeedsRequest.
	}
	it := c.ListMetadataFeeds(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			// TODO: Handle error.
		}
		// TODO: Use resp.
		_ = resp

		// If you need to access the underlying RPC response,
		// you can do so by casting the `Response` as below.
		// Otherwise, remove this line. Only populated after
		// first call to Next(). Not safe for concurrent access.
		_ = it.Response.(*dataplexpb.ListMetadataFeedsResponse)
	}
}

Java

Java

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Java API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.ListMetadataFeedsRequest;
import com.google.cloud.dataplex.v1.LocationName;
import com.google.cloud.dataplex.v1.MetadataFeed;

public class SyncListMetadataFeeds {

  public static void main(String[] args) throws Exception {
    syncListMetadataFeeds();
  }

  public static void syncListMetadataFeeds() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      ListMetadataFeedsRequest request =
          ListMetadataFeedsRequest.newBuilder()
              .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString())
              .setPageSize(883849137)
              .setPageToken("pageToken873572522")
              .setFilter("filter-1274492040")
              .setOrderBy("orderBy-1207110587")
              .build();
      for (MetadataFeed element : catalogServiceClient.listMetadataFeeds(request).iterateAll()) {
        // doThingsWith(element);
      }
    }
  }
}

Node.js

Node.js

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Node.js API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the parent location, in the format
 *  `projects/{project_id_or_number}/locations/{location_id}`
 */
// const parent = 'abc123'
/**
 *  Optional. The maximum number of metadata feeds to return. The service
 *  might return fewer feeds than this value. If unspecified, at most 10 feeds
 *  are returned. The maximum value is 1,000.
 */
// const pageSize = 1234
/**
 *  Optional. The page token received from a previous `ListMetadataFeeds` call.
 *  Provide this token to retrieve the subsequent page of results. When
 *  paginating, all other parameters that are provided to the
 *  `ListMetadataFeeds` request must match the call that provided the
 *  page token.
 */
// const pageToken = 'abc123'
/**
 *  Optional. Filter request. Filters are case-sensitive.
 *  The service supports the following formats:
 *  * `labels.key1 = "value1"`
 *  * `labels:key1`
 *  * `name = "value"`
 *  You can combine filters with `AND`, `OR`, and `NOT` operators.
 */
// const filter = 'abc123'
/**
 *  Optional. The field to sort the results by, either `name` or `create_time`.
 *  If not specified, the ordering is undefined.
 */
// const orderBy = 'abc123'

// Imports the Dataplex library
const {CatalogServiceClient} = require('@google-cloud/dataplex').v1;

// Instantiates a client
const dataplexClient = new CatalogServiceClient();

async function callListMetadataFeeds() {
  // Construct request
  const request = {
    parent,
  };

  // Run request
  const iterable = dataplexClient.listMetadataFeedsAsync(request);
  for await (const response of iterable) {
      console.log(response);
  }
}

callListMetadataFeeds();

Python

Python

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Python 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Python API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_list_metadata_feeds():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.ListMetadataFeedsRequest(
        parent="parent_value",
    )

    # Make the request
    page_result = client.list_metadata_feeds(request=request)

    # Handle the response
    for response in page_result:
        print(response)

REST

如需列出元数据更改 Feed,请使用 projects.locations.metadataFeeds.list 方法。

运行以下命令:

gcurl "https://${DATAPLEX_API}/metadataFeeds"

更新元数据更改 Feed

您可以更新现有元数据更改 Feed 的范围或过滤条件。

C#

C#

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 C# 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog C# API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

using Google.Cloud.Dataplex.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for UpdateMetadataFeed</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void UpdateMetadataFeedRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        UpdateMetadataFeedRequest request = new UpdateMetadataFeedRequest
        {
            MetadataFeed = new MetadataFeed(),
            UpdateMask = new FieldMask(),
            ValidateOnly = false,
        };
        // Make the request
        Operation<MetadataFeed, OperationMetadata> response = catalogServiceClient.UpdateMetadataFeed(request);

        // Poll until the returned long-running operation is complete
        Operation<MetadataFeed, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        MetadataFeed result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<MetadataFeed, OperationMetadata> retrievedResponse = catalogServiceClient.PollOnceUpdateMetadataFeed(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            MetadataFeed retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Go API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


//go:build examples

package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.UpdateMetadataFeedRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#UpdateMetadataFeedRequest.
	}
	op, err := c.UpdateMetadataFeed(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	resp, err := op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	// TODO: Use resp.
	_ = resp
}

Java

Java

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Java API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.MetadataFeed;
import com.google.cloud.dataplex.v1.UpdateMetadataFeedRequest;
import com.google.protobuf.FieldMask;

public class SyncUpdateMetadataFeed {

  public static void main(String[] args) throws Exception {
    syncUpdateMetadataFeed();
  }

  public static void syncUpdateMetadataFeed() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      UpdateMetadataFeedRequest request =
          UpdateMetadataFeedRequest.newBuilder()
              .setMetadataFeed(MetadataFeed.newBuilder().build())
              .setUpdateMask(FieldMask.newBuilder().build())
              .setValidateOnly(true)
              .build();
      MetadataFeed response = catalogServiceClient.updateMetadataFeedAsync(request).get();
    }
  }
}

Node.js

Node.js

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Node.js API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. Update description.
 *  Only fields specified in `update_mask` are updated.
 */
// const metadataFeed = {}
/**
 *  Optional. Mask of fields to update.
 */
// const updateMask = {}
/**
 *  Optional. Only validate the request, but do not perform mutations.
 *  The default is false.
 */
// const validateOnly = true

// Imports the Dataplex library
const {CatalogServiceClient} = require('@google-cloud/dataplex').v1;

// Instantiates a client
const dataplexClient = new CatalogServiceClient();

async function callUpdateMetadataFeed() {
  // Construct request
  const request = {
    metadataFeed,
  };

  // Run request
  const [operation] = await dataplexClient.updateMetadataFeed(request);
  const [response] = await operation.promise();
  console.log(response);
}

callUpdateMetadataFeed();

Python

Python

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Python 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Python API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_update_metadata_feed():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    metadata_feed = dataplex_v1.MetadataFeed()
    metadata_feed.pubsub_topic = "pubsub_topic_value"

    request = dataplex_v1.UpdateMetadataFeedRequest(
        metadata_feed=metadata_feed,
    )

    # Make the request
    operation = client.update_metadata_feed(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

REST

如需更新元数据更改 Feed,请使用 projects.locations.metadataFeeds.patch 方法。

运行以下命令以更新元数据更改 Feed,从而移除条目类型过滤条件:

gcurl -X PATCH -d "$(cat <<EOF
{
  "filter": {
    "entryTypes": []
  }
}
EOF
)" "https://${DATAPLEX_API}/metadataFeeds/FEED_ID?updateMask=filter"

替换以下内容:

  • FEED_ID:要更新的元数据更改 Feed ID,例如 example-feed

删除元数据更改 Feed

如果您不再需要接收通知,可以删除元数据更改 Feed。

删除元数据更改 Feed 会停止该 Feed 向您的 Pub/Sub 主题发布新的元数据更改。不过,此操作不会删除主题或与 Feed 关联的订阅。如果不再需要这些文件,您必须手动将其删除。

在删除订阅源或订阅之前,请确保订阅者应用已处理 Pub/Sub 订阅中的所有未处理的消息。

C#

C#

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 C# 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog C# API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

using Google.Cloud.Dataplex.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;

public sealed partial class GeneratedCatalogServiceClientSnippets
{
    /// <summary>Snippet for DeleteMetadataFeed</summary>
    /// <remarks>
    /// This snippet has been automatically generated and should be regarded as a code template only.
    /// It will require modifications to work:
    /// - It may require correct/in-range values for request initialization.
    /// - It may require specifying regional endpoints when creating the service client as shown in
    ///   https://cloud.google.com/dotnet/docs/reference/help/client-configuration#endpoint.
    /// </remarks>
    public void DeleteMetadataFeedRequestObject()
    {
        // Create client
        CatalogServiceClient catalogServiceClient = CatalogServiceClient.Create();
        // Initialize request argument(s)
        DeleteMetadataFeedRequest request = new DeleteMetadataFeedRequest
        {
            MetadataFeedName = MetadataFeedName.FromProjectLocationMetadataFeed("[PROJECT]", "[LOCATION]", "[METADATA_FEED]"),
        };
        // Make the request
        Operation<Empty, OperationMetadata> response = catalogServiceClient.DeleteMetadataFeed(request);

        // Poll until the returned long-running operation is complete
        Operation<Empty, OperationMetadata> completedResponse = response.PollUntilCompleted();
        // Retrieve the operation result
        Empty result = completedResponse.Result;

        // Or get the name of the operation
        string operationName = response.Name;
        // This name can be stored, then the long-running operation retrieved later by name
        Operation<Empty, OperationMetadata> retrievedResponse = catalogServiceClient.PollOnceDeleteMetadataFeed(operationName);
        // Check if the retrieved long-running operation has completed
        if (retrievedResponse.IsCompleted)
        {
            // If it has completed, then access the result
            Empty retrievedResult = retrievedResponse.Result;
        }
    }
}

Go

Go

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Go 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Go API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证


//go:build examples

package main

import (
	"context"

	dataplex "cloud.google.com/go/dataplex/apiv1"
	dataplexpb "cloud.google.com/go/dataplex/apiv1/dataplexpb"
)

func main() {
	ctx := context.Background()
	// This snippet has been automatically generated and should be regarded as a code template only.
	// It will require modifications to work:
	// - It may require correct/in-range values for request initialization.
	// - It may require specifying regional endpoints when creating the service client as shown in:
	//   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
	c, err := dataplex.NewCatalogClient(ctx)
	if err != nil {
		// TODO: Handle error.
	}
	defer c.Close()

	req := &dataplexpb.DeleteMetadataFeedRequest{
		// TODO: Fill request struct fields.
		// See https://pkg.go.dev/cloud.google.com/go/dataplex/apiv1/dataplexpb#DeleteMetadataFeedRequest.
	}
	op, err := c.DeleteMetadataFeed(ctx, req)
	if err != nil {
		// TODO: Handle error.
	}

	err = op.Wait(ctx)
	if err != nil {
		// TODO: Handle error.
	}
}

Java

Java

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Java 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Java API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

import com.google.cloud.dataplex.v1.CatalogServiceClient;
import com.google.cloud.dataplex.v1.DeleteMetadataFeedRequest;
import com.google.cloud.dataplex.v1.MetadataFeedName;
import com.google.protobuf.Empty;

public class SyncDeleteMetadataFeed {

  public static void main(String[] args) throws Exception {
    syncDeleteMetadataFeed();
  }

  public static void syncDeleteMetadataFeed() throws Exception {
    // This snippet has been automatically generated and should be regarded as a code template only.
    // It will require modifications to work:
    // - It may require correct/in-range values for request initialization.
    // - It may require specifying regional endpoints when creating the service client as shown in
    // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
    try (CatalogServiceClient catalogServiceClient = CatalogServiceClient.create()) {
      DeleteMetadataFeedRequest request =
          DeleteMetadataFeedRequest.newBuilder()
              .setName(MetadataFeedName.of("[PROJECT]", "[LOCATION]", "[METADATA_FEED]").toString())
              .build();
      catalogServiceClient.deleteMetadataFeedAsync(request).get();
    }
  }
}

Node.js

Node.js

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Node.js 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Node.js API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

/**
 * This snippet has been automatically generated and should be regarded as a code template only.
 * It will require modifications to work.
 * It may require correct/in-range values for request initialization.
 * TODO(developer): Uncomment these variables before running the sample.
 */
/**
 *  Required. The resource name of the metadata feed, in the format
 *  `projects/{project_id_or_number}/locations/{location_id}/MetadataFeeds/{metadata_feed_id}`.
 */
// const name = 'abc123'

// Imports the Dataplex library
const {CatalogServiceClient} = require('@google-cloud/dataplex').v1;

// Instantiates a client
const dataplexClient = new CatalogServiceClient();

async function callDeleteMetadataFeed() {
  // Construct request
  const request = {
    name,
  };

  // Run request
  const [operation] = await dataplexClient.deleteMetadataFeed(request);
  const [response] = await operation.promise();
  console.log(response);
}

callDeleteMetadataFeed();

Python

Python

试用此示例之前,请按照《Knowledge Catalog 快速入门:使用客户端库》中的 Python 设置说明进行操作。 如需了解详情,请参阅 Knowledge Catalog Python API 参考文档

如需向 Knowledge Catalog 进行身份验证,请设置应用默认凭据。如需了解详情,请参阅为本地开发环境设置身份验证

# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
#   client as shown in:
#   https://googleapis.dev/python/google-api-core/latest/client_options.html
from google.cloud import dataplex_v1


def sample_delete_metadata_feed():
    # Create a client
    client = dataplex_v1.CatalogServiceClient()

    # Initialize request argument(s)
    request = dataplex_v1.DeleteMetadataFeedRequest(
        name="name_value",
    )

    # Make the request
    operation = client.delete_metadata_feed(request=request)

    print("Waiting for operation to complete...")

    response = operation.result()

    # Handle the response
    print(response)

REST

如需删除元数据更改 Feed,请使用 projects.locations.metadataFeeds.delete 方法。

运行以下命令:

gcurl -X DELETE \
"https://${DATAPLEX_API}/metadataFeeds/FEED_ID"

替换以下内容:

  • FEED_ID:要删除的元数据更改 Feed ID,例如 example-feed

使用通知消息

配置元数据更改 Feed 后,当元数据发生更改时,Knowledge Catalog 会将消息发布到指定的 Pub/Sub 主题。如需使用这些消息,请针对相应主题创建 Pub/Sub 订阅。

例如,您可以创建拉取订阅,并使用 Google Cloud CLI 查看消息:

  1. 创建订阅:

    gcloud pubsub subscriptions create SUBSCRIPTION_ID --topic=TOPIC_ID
    

    替换以下内容:

    • SUBSCRIPTION_ID:您要创建的订阅 ID
    • TOPIC_ID:元数据更改 Feed 消息发布到的 Pub/Sub 主题 ID。
  2. 从订阅中拉取消息:

    gcloud pubsub subscriptions pull SUBSCRIPTION_ID --auto-ack --limit=10
    

    替换以下内容:

    • SUBSCRIPTION_ID:您要从中拉取消息的订阅 ID

如需详细了解如何处理 Pub/Sub 消息,请参阅接收来自拉取订阅的消息。如需了解消息格式,请参阅数据载荷

后续步骤