gcloud CLI를 사용하여 Pub/Sub에서 메시지 게시 및 수신

이 페이지에서는 Google Cloud CLI를 사용하여 Pub/Sub에서 다음 작업을 수행하는 방법을 보여줍니다.

  • 주제 및 구독을 만듭니다.
  • 주제에 메시지를 게시합니다.
  • 구독에서 메시지를 수신합니다.

Google Cloud 콘솔에서 이 태스크에 대한 단계별 안내를 직접 수행하려면 둘러보기를 클릭합니다.

둘러보기


시작하기 전에

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Set up a Google Cloud console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Pub/Sub API for that project.

    You can view and manage these resources at any time in the Google Cloud console.

  3. Install the Google Cloud CLI.

  4. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

  5. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

    gcloud init
  6. Set up a Google Cloud console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Pub/Sub API for that project.

    You can view and manage these resources at any time in the Google Cloud console.

  7. Install the Google Cloud CLI.

  8. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

  9. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

    gcloud init
  10. 주제 만들기

    ID가 my-topic인 주제를 만듭니다.

    gcloud pubsub topics create my-topic

    구독 만들기

    ID가 my-sub인 구독을 만들고 my-topic에 연결합니다.

    gcloud pubsub subscriptions create my-sub --topic=my-topic

    메시지 게시

    my-topic에 메시지를 게시합니다.

    gcloud pubsub topics publish my-topic --message="hello"

    메시지 수신

    my-sub에서 메시지를 수신합니다.

    gcloud pubsub subscriptions pull my-sub --auto-ack

    gcloud CLI는 명령줄에 메시지를 인쇄합니다.

    어땠나요?

    다음 단계