주제의 스키마 버전 삭제

이 문서에서는 Pub/Sub 주제의 스키마 버전을 삭제하는 방법을 설명합니다. 스키마를 삭제하면 스키마와 연결된 모든 버전도 삭제됩니다.

시작하기 전에

필수 역할 및 권한

스키마 버전을 삭제하고 관리하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 Pub/Sub 편집자(roles/pubsub.editor) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 액세스 관리를 참조하세요.

이 사전 정의된 역할에는 스키마 버전을 삭제하고 관리하는 데 필요한 권한이 포함되어 있습니다. 필요한 정확한 권한을 보려면 필수 권한 섹션을 확장하세요.

필수 권한

스키마 버전을 삭제하고 관리하려면 다음 권한이 필요합니다.

  • 스키마 만들기: pubsub.schemas.create
  • 주제에 스키마 연결: pubsub.schemas.attach
  • 스키마 버전 커밋: pubsub.schemas.commit
  • 스키마 또는 스키마 버전 삭제: pubsub.schemas.delete
  • 스키마 또는 스키마 버전 가져오기: pubsub.schemas.get
  • 스키마 나열: pubsub.schemas.list
  • 스키마 버전 나열: pubsub.schemas.listRevisions
  • 스키마 롤백: pubsub.schemas.rollback
  • 메시지 유효성 검사: pubsub.schemas.validate
  • 스키마의 IAM 정책 가져오기: pubsub.schemas.getIamPolicy
  • 스키마의 IAM 정책 구성: pubsub.schemas.setIamPolicy

커스텀 역할이나 다른 사전 정의된 역할을 사용하여 이 권한을 부여받을 수도 있습니다.

사용자, 그룹, 도메인, 서비스 계정과 같은 주 구성원에 역할 및 권한을 부여할 수 있습니다. 한 프로젝트에서 스키마를 만들고 이를 다른 프로젝트에 있는 주제에 연결할 수 있습니다. 각 프로젝트에 필요한 권한이 있는지 확인합니다.

스키마 버전 삭제

다음은 스키마 버전 삭제에 대한 몇 가지 중요한 가이드라인입니다.

  • 스키마에서 스키마 버전을 한 개 또는 여러 개 삭제할 수 있습니다.

  • 스키마에 버전이 하나만 있으면 해당 버전을 삭제할 수 없습니다. 대신 스키마를 삭제합니다.

  • 스키마를 삭제하면 스키마와 연결된 모든 버전도 삭제됩니다.

  • 스키마를 삭제하면 해당 스키키와 연결된 주제에 대한 메시지 게시가 실패합니다.

  • 한 주제의 첫 번째 버전으로 지정된 스키마 버전을 삭제하면 유효성을 검사할 때 다음 버전이 대신 사용됩니다.

    한 주제의 마지막 버전으로 지정된 스키마 버전을 삭제하면 유효성을 검사할 때 이전 스키마 버전이 대신 사용됩니다.

    유효성 검사를 위해 주제에 지정된 버전 범위 내에 포함된 스키마 버전을 삭제하면 해당 버전을 건너뜁니다.

Google Cloud 콘솔, gcloud CLI, Pub/Sub API, Cloud 클라이언트 라이브러리를 사용하여 스키마 버전을 삭제할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 Pub/Sub 스키마 페이지로 이동합니다.

    스키마로 이동

  2. 기존 스키마의 이름을 클릭합니다.

    스키마의 스키마 세부정보 페이지가 열립니다.

  3. 삭제할 버전을 선택합니다. 여러 버전을 선택할 수도 있습니다.

  4. 버전 삭제를 클릭합니다.

  5. 삭제 작업을 확인합니다.

gcloud

gcloud pubsub schemas delete-revision SCHEMA_NAME@REVISION_ID

각 항목의 의미는 다음과 같습니다.

  • REVISION_ID는 롤백할 버전입니다.

REST

스키마 버전을 삭제하려면 다음과 같이 DELETE 요청을 보냅니다.

POST https://pubsub.googleapis.com/v1/projects/PROJECT_ID/schemas/SCHEMA_ID@REVISION_ID:deleteRevision
Authorization: Bearer $(gcloud auth application-default print-access-token)
Content-Type: application/json --data @response-body.json

응답 본문에는 삭제된 스키마 리소스의 JSON 표현이 포함되어야 합니다.

C++

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 C++ 설정 안내를 따르세요. 자세한 내용은 Pub/Sub C++ API 참고 문서를 확인하세요.

namespace pubsub = ::google::cloud::pubsub;
[](pubsub::SchemaServiceClient client, std::string const& project_id,
   std::string const& schema_id, std::string const& revision_id) {
  std::string const schema_id_with_revision = schema_id + "@" + revision_id;

  google::pubsub::v1::DeleteSchemaRevisionRequest request;
  request.set_name(
      pubsub::Schema(project_id, schema_id_with_revision).FullName());
  auto schema = client.DeleteSchemaRevision(request);
  if (!schema) throw std::move(schema).status();

  std::cout << "Deleted schema. Its metadata is:" << "\n"
            << schema->DebugString() << "\n";
}

Go

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 Go 설정 안내를 따르세요. 자세한 내용은 Pub/Sub Go API 참고 문서를 참조하세요.

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/pubsub"
)

func deleteSchemaRevision(w io.Writer, projectID, schemaID, revisionID string) error {
	// projectID := "my-project-id"
	// schemaID := "my-schema-id"
	// revisionID := "my-revision-id"
	ctx := context.Background()
	client, err := pubsub.NewSchemaClient(ctx, projectID)
	if err != nil {
		return fmt.Errorf("pubsub.NewSchemaClient: %w", err)
	}
	defer client.Close()

	if _, err := client.DeleteSchemaRevision(ctx, schemaID, revisionID); err != nil {
		return fmt.Errorf("client.DeleteSchema revision: %w", err)
	}
	fmt.Fprintf(w, "Deleted a schema revision: %s@%s", schemaID, revisionID)
	return nil
}

Java

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 자바 설정 안내를 따르세요. 자세한 내용은 Pub/Sub Java API 참고 문서를 참조하세요.


import com.google.api.gax.rpc.NotFoundException;
import com.google.cloud.pubsub.v1.SchemaServiceClient;
import com.google.pubsub.v1.DeleteSchemaRevisionRequest;
import com.google.pubsub.v1.SchemaName;
import java.io.IOException;

public class DeleteSchemaRevisionExample {

  public static void main(String... args) throws Exception {
    // TODO(developer): Replace these variables before running the sample.
    String projectId = "your-project-id";
    String schemaId = "your-schema-id@your-revision-id";

    deleteSchemaRevisionExample(projectId, schemaId);
  }

  public static void deleteSchemaRevisionExample(String projectId, String schemaId)
      throws IOException {
    SchemaName schemaName = SchemaName.of(projectId, schemaId);

    try (SchemaServiceClient schemaServiceClient = SchemaServiceClient.create()) {

      DeleteSchemaRevisionRequest request =
          DeleteSchemaRevisionRequest.newBuilder().setName(schemaName.toString()).build();

      schemaServiceClient.deleteSchemaRevision(request);

      System.out.println("Deleted a schema revision:" + schemaName);

    } catch (NotFoundException e) {
      System.out.println(schemaName + "not found.");
    }
  }
}

Python

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 Python 설정 안내를 따르세요. 자세한 내용은 Pub/Sub Python API 참고 문서를 참조하세요.

from google.api_core.exceptions import NotFound
from google.cloud.pubsub import SchemaServiceClient

# TODO(developer): Replace these variables before running the sample.
# project_id = "your-project-id"
# schema_id = "your-schema-id"
# revision_id = "your-revision-id"

schema_client = SchemaServiceClient()
schema_path = schema_client.schema_path(project_id, schema_id + "@" + revision_id)

try:
    schema_client.delete_schema_revision(request={"name": schema_path})
    print(f"Deleted a schema revision:\n{schema_path}")
except NotFound:
    print(f"{schema_id} not found.")

Node.js

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 Node.js 설정 안내를 따르세요. 자세한 내용은 Pub/Sub Node.js API 참고 문서를 참조하세요.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID';
// const revisionId = 'YOUR_REVISION_ID';

// Imports the Google Cloud client library
const {PubSub} = require('@google-cloud/pubsub');

// Creates a client; cache this for further use
const pubSubClient = new PubSub();

async function deleteSchemaRevision(schemaNameOrId, revisionId) {
  // Get the fully qualified schema name.
  const schema = pubSubClient.schema(schemaNameOrId);
  const name = await schema.getName();

  // Use the gapic client to delete the schema revision.
  const schemaClient = await pubSubClient.getSchemaClient();
  await schemaClient.deleteSchemaRevision({
    name: `${name}@${revisionId}`,
  });

  console.log(`Schema ${name} revision ${revisionId} deleted.`);
}

Node.js

이 샘플을 시도하기 전에 빠른 시작: 클라이언트 라이브러리 사용의 Node.js 설정 안내를 따르세요. 자세한 내용은 Pub/Sub Node.js API 참고 문서를 참조하세요.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const schemaNameOrId = 'YOUR_SCHEMA_NAME_OR_ID';
// const revisionId = 'YOUR_REVISION_ID';

// Imports the Google Cloud client library
import {PubSub} from '@google-cloud/pubsub';

// Creates a client; cache this for further use
const pubSubClient = new PubSub();

async function deleteSchemaRevision(
  schemaNameOrId: string,
  revisionId: string
) {
  // Get the fully qualified schema name.
  const schema = pubSubClient.schema(schemaNameOrId);
  const name = await schema.getName();

  // Use the gapic client to delete the schema revision.
  const schemaClient = await pubSubClient.getSchemaClient();
  await schemaClient.deleteSchemaRevision({
    name: `${name}@${revisionId}`,
  });

  console.log(`Schema ${name} revision ${revisionId} deleted.`);
}

다음 단계