メタデータ変更フィードで通知を受け取る

このドキュメントでは、Knowledge Catalog(旧称 Dataplex Universal Catalog)のメタデータ変更フィードを構成して、Knowledge Catalog 内のメタデータが作成、更新、削除されたときに Pub/Sub を介して通知を受け取る方法について説明します。

メタデータ変更フィードの詳細については、メタデータ変更フィードの概要をご覧ください。

始める前に

Pub/SubDataplex API について理解する。

  1. Dataplex API と Pub/Sub API を有効にします。

    API を有効にするために必要なロール

    API を有効にするには、serviceusage.services.enable 権限を含む Service Usage 管理者 IAM ロール(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

必要なロールと権限

メタデータ変更フィードを構成するには、自分と Knowledge Catalog サービス アカウントに必要な IAM ロールと権限があることを確認します。

ユーザーの役割と権限

メタデータをエクスポートし、メタデータ変更フィード メッセージにアクセスするために必要な権限を取得するには、プロジェクトまたは組織に対する次の IAM ロールを付与するよう管理者に依頼してください。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

これらの事前定義ロールには、メタデータのエクスポートとメタデータ変更フィード メッセージへのアクセスに必要な権限が含まれています。必要とされる正確な権限については、「必要な権限」セクションを開いてご確認ください。

必要な権限

メタデータをエクスポートしてメタデータ変更フィード メッセージにアクセスするには、次の権限が必要です。

  • メタデータをエクスポートする:
    • プロジェクトに対する dataplex.metadataFeeds.create
    • フィードのスコープを定義するリソース(組織、プロジェクト、エントリ グループ)に対する dataplex.entryGroups.export
    • プロジェクトに対する resourcemanager.projects.get
    • プロジェクトに対する resourcemanager.projects.list
  • メタデータ変更フィード メッセージにアクセスする:
    • サブスクリプションに対する pubsub.subscriptions.consume
    • トピックに対する pubsub.topics.attachSubscription

カスタムロールや他の事前定義ロールを使用して、これらの権限を取得することもできます。

Knowledge Catalog サービス アカウントのロールと権限

Knowledge Catalog サービス アカウントにメタデータ変更フィード メッセージを公開するために必要な権限が付与されていることを確認するには、Pub/Sub トピックに対する Pub/Sub パブリッシャー(roles/pubsub.publisher)と Pub/Sub 閲覧者(roles/pubsub.viewer)の IAM ロールを Knowledge Catalog サービス アカウントに付与するよう管理者に依頼してください。

ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

この事前定義ロールには、メタデータ変更フィード メッセージのパブリッシュに必要な pubsub.topics.publish 権限と pubsub.topics.get 権限が含まれています。

管理者は、カスタムロールや他の事前定義ロールを使用して、この権限を Knowledge Catalog サービス アカウントに付与することもできます。

Knowledge Catalog サービス アカウントに権限を付与する

Knowledge Catalog のサービス エージェントは、Dataplex API を有効にすると作成されます。サービス エージェントは、次のメール 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。
  • PROJECT_NUMBER: サービス アカウントが配置されている Knowledge Catalog プロジェクトのプロジェクト番号。

コンソール

  1. Google Cloud コンソールで、Pub/Sub の [トピック] ページに移動します。

    トピックに移動

  2. メタデータ フィード通知に使用しているトピックを選択し、必要に応じて [情報パネルを表示] をクリックします。

  3. [権限] タブで、[プリンシパルを追加] をクリックします。

  4. [新しいプリンシパル] フィールドに、Knowledge Catalog サービス アカウント(service-PROJECT_NUMBER@gcp-sa-dataplex.iam.gserviceaccount.com)を入力します。

  5. [ロールを割り当てる] フィールドで、[Pub/Sub パブリッシャー] を選択します。

  6. [別のロールを追加] をクリックし、[Pub/Sub 閲覧者] を選択します。

  7. [保存] をクリックします。

メタデータ変更フィードを作成する

通知を生成する変更を制御するには、特定のリソースをモニタリングするようにメタデータ変更フィードを構成します。これを行うには、組織全体、特定のプロジェクト、特定のエントリ グループなどのスコープを指定します。スコープを使用すると、モニタリングするリソースを定義できます。フィルタを使用すると、Knowledge Catalog が通知を送信するタイミングをさらに絞り込むことができます。

詳細については、メタデータ変更フィードをご覧ください。

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

メタデータ変更フィードを作成するには、projects.locations.metadataFeeds.create メソッドを使用します。

組織スコープ

次のコマンドを実行して、組織全体をモニタリングするメタデータ変更フィードを作成します。

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: メタデータ変更フィード メッセージが公開される Pub/Sub トピック ID(例: example-topic
  • FEED_ID: 作成するメタデータ変更フィード ID(例: example-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: メタデータ変更フィード メッセージが公開される Pub/Sub トピック ID(例: example-topic
  • FEED_ID: 作成するメタデータ変更フィード ID(例: example-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: フィードを作成するロケーション(例: us-central1
  • ENTRY_GROUP_ID: モニタリングするエントリ グループ ID(例: example-entry-group
  • TOPIC_ID: メタデータ変更フィード メッセージが公開される Pub/Sub トピック ID(例: example-topic
  • FEED_ID: 作成するメタデータ変更フィード ID(例: example-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: メタデータ変更フィード メッセージが公開される Pub/Sub トピック ID(例: example-topic
  • FEED_ID: 作成するメタデータ変更フィード 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
}

メタデータの変更フィードを表示する

メタデータ変更フィードの詳細を表示できます。

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

メタデータ変更フィードを表示するには、projects.locations.metadataFeeds.get メソッドを使用します。

次のコマンドを実行します。

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

次のように置き換えます。

  • FEED_ID: 表示するメタデータ変更フィード ID(例: example-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

メタデータ変更フィードを一覧表示するには、projects.locations.metadataFeeds.list メソッドを使用します。

次のコマンドを実行します。

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

メタデータ変更フィードを更新する

既存のメタデータ変更フィードのスコープまたはフィルタを更新できます。

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

メタデータ変更フィードを更新するには、projects.locations.metadataFeeds.patch メソッドを使用します。

次のコマンドを実行して、メタデータ変更フィードを更新し、エントリ タイプ フィルタを削除します。

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

次のように置き換えます。

  • FEED_ID: 更新するメタデータ変更フィード ID(例: example-feed

メタデータ変更フィードを削除する

通知を受け取る必要がなくなった場合は、メタデータ変更フィードを削除できます。

メタデータ変更フィードを削除すると、フィードが新しいメタデータ変更を Pub/Sub トピックにパブリッシュしなくなります。ただし、フィードに関連付けられているトピックやサブスクリプションは削除されません。不要になった場合は、手動で削除する必要があります。

フィードまたはサブスクリプションを削除する前に、サブスクライバー アプリケーションが 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

メタデータ変更フィードを削除するには、projects.locations.metadataFeeds.delete メソッドを使用します。

次のコマンドを実行します。

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

次のように置き換えます。

  • FEED_ID: 削除するメタデータ変更フィード ID(例: example-feed

通知メッセージを使用する

メタデータ変更フィードを構成すると、メタデータの変更が発生したときに、Knowledge Catalog は指定された Pub/Sub トピックにメッセージをパブリッシュします。これらのメッセージを使用するには、トピックに対する Pub/Sub サブスクリプションを作成します。

たとえば、pull サブスクリプションを作成し、Google Cloud CLI を使用してメッセージを表示できます。

  1. サブスクリプションを作成します。

    gcloud pubsub subscriptions create SUBSCRIPTION_ID --topic=TOPIC_ID
    

    次のように置き換えます。

    • SUBSCRIPTION_ID: 作成するサブスクリプション ID
    • TOPIC_ID: メタデータ変更フィード メッセージが公開される Pub/Sub トピック ID。
  2. サブスクリプションからメッセージを pull します。

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

    次のように置き換えます。

    • SUBSCRIPTION_ID: メッセージを pull するサブスクリプション ID

Pub/Sub メッセージの処理の詳細については、プル サブスクリプションからメッセージを受信するをご覧ください。メッセージ形式については、データ ペイロードをご覧ください。

次のステップ