v1 刪除訂閱項目 (已淘汰)

(DEPRECATED) Delete subscription

程式碼範例

Go

在試用這個範例之前,請先按照「使用用戶端程式庫的 Pub/Sub 快速入門導覽課程」中的 Go 設定操作說明進行操作。詳情請參閱 Pub/Sub Go API 參考文件

如要向 Pub/Sub 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

import (
	"context"
	"fmt"
	"io"

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

func delete(w io.Writer, projectID, subID string) error {
	// projectID := "my-project-id"
	// subID := "my-sub"
	ctx := context.Background()
	client, err := pubsub.NewClient(ctx, projectID)
	if err != nil {
		return fmt.Errorf("pubsub.NewClient: %w", err)
	}
	defer client.Close()

	sub := client.Subscription(subID)
	if err := sub.Delete(ctx); err != nil {
		return fmt.Errorf("Delete: %w", err)
	}
	fmt.Fprintf(w, "Subscription %q deleted.", subID)
	return nil
}

Ruby

在試用這個範例之前,請先按照「使用用戶端程式庫的 Pub/Sub 快速入門導覽課程」中的 Ruby 設定操作說明進行操作。詳情請參閱 Pub/Sub Ruby API 參考文件

如要向 Pub/Sub 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。

# subscription_id = "your-subscription-id"

pubsub = Google::Cloud::Pubsub.new

subscription = pubsub.subscription subscription_id
subscription.delete

puts "Subscription #{subscription_id} deleted."

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 瀏覽器範例