ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ Pub/Sub์์ ๋ฉ์์ง ๊ฒ์ ๋ฐ ์์
Pub/Sub ์๋น์ค๋ฅผ ํ์ฉํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์ผ๋ก ์์ ์ ์ด๊ณ ์ ์ํ๋ฉฐ ๋น๋๊ธฐ์ ์ธ ๋ฐฉ์์ผ๋ก ๋ฉ์์ง๋ฅผ ์ฃผ๊ณ ๋ฐ์ ์ ์์ต๋๋ค. ๋ค์์ ์ด๋ฒคํธ ์ํ์ค์ ๋๋ค.
- ๋ฐ์ดํฐ ์ ์์๋ Pub/Sub ์ฃผ์ ์ ๋ฉ์์ง๋ฅผ ๊ฒ์ํฉ๋๋ค.
- ๊ตฌ๋ ์ ํด๋ผ์ด์ธํธ๊ฐ ํด๋น ์ฃผ์ ์ ๋ํ ๊ตฌ๋ ์ ์์ฑํ๊ณ ๊ตฌ๋ ์ด ์ ๋ฌํ๋ ๋ฉ์์ง๋ฅผ ์๋นํ๊ฒ ๋ฉ๋๋ค.
Google Cloud ์ฝ์, Cloud Shell, ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋๋ REST API ๋ฐฉ๋ฒ ์ค์์ ํ๋๋ฅผ ์ฌ์ฉํ์ฌ Pub/Sub ํ๊ฒฝ์ ์ค์ ํ ์ ์์ต๋๋ค. ์ด ํ์ด์ง์์๋ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ์ฌ Pub/Sub๋ก ๋ฉ์์ง ๊ฒ์๋ฅผ ์์ํ๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
Pub/Sub๋ ๋์ ์์ค ๋ฐ ๋ฎ์ ์์ค์ ์๋ ์์ฑ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ ๊ณตํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก ์ด ๋น ๋ฅธ ์์์์์ ๊ฐ์ด ๋์ ์์ค์ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
Google Cloud ์ฝ์์์ ์ด ํ์คํฌ์ ๋ํ ๋จ๊ณ๋ณ ์๋ด๋ฅผ ์ง์ ์ํํ๋ ค๋ฉด ๋๋ฌ๋ณด๊ธฐ๋ฅผ ํด๋ฆญํฉ๋๋ค.
์์ํ๊ธฐ ์ ์
- 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.
-
Install the Google Cloud CLI.
-
์ธ๋ถ ID ๊ณต๊ธ์ ์ฒด(IdP)๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋จผ์ ์ ํด ID๋ก gcloud CLI์ ๋ก๊ทธ์ธํด์ผ ํฉ๋๋ค.
-
gcloud CLI๋ฅผ ์ด๊ธฐํํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Pub/Sub API:
gcloud services enable pubsub.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/pubsub.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user accountโfor example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
-
Install the Google Cloud CLI.
-
์ธ๋ถ ID ๊ณต๊ธ์ ์ฒด(IdP)๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ ๋จผ์ ์ ํด ID๋ก gcloud CLI์ ๋ก๊ทธ์ธํด์ผ ํฉ๋๋ค.
-
gcloud CLI๋ฅผ ์ด๊ธฐํํ๋ ค๋ฉด ๋ค์ ๋ช ๋ น์ด๋ฅผ ์คํํฉ๋๋ค.
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Pub/Sub API:
gcloud services enable pubsub.googleapis.com
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/pubsub.admin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user accountโfor example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
- ์ด ๊ฐ์ด๋์์ ์ฌ์ฉํ ๋ฆฌ์์ค ๋น์ฉ์ด Google Cloud ๊ณ์ ์ ์ฒญ๊ตฌ๋์ง ์๋๋ก ํ๋ ค๋ฉด ๋ช
๋ น์ค์ ์ฌ์ฉํ์ฌ ์ฃผ์ ์ ๊ตฌ๋
์ ์ญ์ ํ๋ฉด ๋ฉ๋๋ค.
gcloud pubsub subscriptions delete my-sub gcloud pubsub topics delete my-topic
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
์ด ํ์ด์ง์์ ์ค๋ช ํ๋ Pub/Sub ๊ฐ๋ ์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Pub/Sub ์๋น์ค์ ๊ธฐ๋ณธ์ฌํญ ์ฝ์ด๋ณด๊ธฐ
๋ณ๋์ ๋ ๊ตฌ๋ ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ฒ์ํ๋ ๊ฒ์์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค์ด ์ผ๋๋ค Pub/Sub ์์คํ ์ ๋น๋ํ๋ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
gcloud CLI ๋๋ ์ฝ์์ ์ฌ์ฉํ๋ ๋ค๋ฅธ Pub/Sub ๋น ๋ฅธ ์์ ์ฌ์ฉํด ๋ณด๊ธฐ
์ฃผ์ ๋ฅผ ๋ง๋ค๊ณ ๋ฉ์์ง๋ฅผ ๊ฒ์ํ๋ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
Pub/Sub API ์์ธํ ์์๋ณด๊ธฐ
Kotlin์ ์ฌ์ฉํ์ฌ Pub/Sub๋ฅผ ์คํํ๋ ๋ฐฉ๋ฒ ์์๋ณด๊ธฐ
ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น
๋ค์ ์ํ์ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ค๋๋ค.
Python
Python ๊ฐ๋ฐ ํ๊ฒฝ ์ค์ ์ ๊ดํ ์์ธํ ๋ด์ฉ์ Python ๊ฐ๋ฐ ํ๊ฒฝ ์ค์ ๊ฐ์ด๋๋ฅผ ์ฐธ์กฐํ์ธ์.
# ensure that you are using virtualenv
# as described in the python dev setup guide
pip install --upgrade google-cloud-pubsub
C++
C++ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค์น์ ๋ํ ์์ธํ ๋ด์ฉ์ GitHub README
๋ฅผ ์ฐธ๊ณ ํ์ธ์.
C#
Install-Package Google.Cloud.PubSub.V1 -Pre
Go
go get cloud.google.com/go/pubsub
์๋ฐ
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
npm install @google-cloud/pubsub
PHP
composer require google/cloud-pubsub
Ruby
gem install google-cloud-pubsub
์ฃผ์ ๋ฐ ๊ตฌ๋ ๋ง๋ค๊ธฐ
์ฃผ์ ๋ฅผ ๋ง๋ค๋ฉด ์ฃผ์ ๋ฅผ ๊ตฌ๋ ํ๊ฑฐ๋ ์ฃผ์ ์ ๊ฒ์ํ ์ ์์ต๋๋ค.
๋ค์ gcloud pubsub topics create
๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ my-topic
์ด๋ผ๋ ์ฃผ์ ๋ฅผ ๋ง๋ญ๋๋ค. ๋จ์ ํํ ๋ฆฌ์ผ ๋ถ๋ถ์์ ์ฐธ์กฐ๋๋ฏ๋ก ์ฃผ์ ์ด๋ฆ์ ๋ณ๊ฒฝํ์ง ๋ง์ธ์.
gcloud pubsub topics create my-topic
gcloud pubsub subscriptions
create
๋ช
๋ น์ด๋ฅผ ์ฌ์ฉํ์ฌ ๊ตฌ๋
์ ๋ง๋ญ๋๋ค. ๊ตฌ๋
์ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ตฌ๋
์ด ์์ฑ๋ ์ดํ์ ์ฃผ์ ์ ๊ฒ์๋ ๋ฉ์์ง๋ง ์ฌ์ฉํ ์ ์์ต๋๋ค.
gcloud pubsub subscriptions create my-sub --topic my-topic
๋ฉ์์ง ๊ฒ์
๋ค์ ์ํ์ ์คํํ๊ธฐ ์ ์ ์ฃผ์ ์ฒ๋ฆฌ๋ฅผ ์ญ์ ํ๊ณ ์ฝ๋์ ํ์๋ ํ์ ๊ฐ์ ์ฑ์์ผ ํฉ๋๋ค. ์ด๋ ์ด์ ์ ๋ง๋ ํ๋ก์ ํธ ๋ฐ Pub/Sub ๋ฆฌ์์ค์ ์ํ์ ์ฐ๊ฒฐํ๋ ๋ฐ ํ์ํฉ๋๋ค.
์ฃผ์ ID์ my-topic
์ ์ฌ์ฉํฉ๋๋ค.
Python
C++
C#
Go
Java
Node.js
Node.js
PHP
Ruby
๋ฉ์์ง ์์ ํ๊ธฐ
๋ฐฉ๊ธ ๊ฒ์ํ ๋ฉ์์ง๋ฅผ ๊ตฌ๋ ์๊ฐ ๊ฐ์ ธ์ค๋๋ก ์ค์ ํฉ๋๋ค. ๋ชจ๋ ๊ตฌ๋ ์๋ ๊ตฌ์ฑ ๊ฐ๋ฅํ ๊ธฐ๊ฐ ์์ ๊ฐ ๋ฉ์์ง๋ฅผ ํ์ธํด์ผ ํฉ๋๋ค. ํ์ธํ์ง ์์ ๋ฉ์์ง๋ ๋ค์ ์ ์ก๋ฉ๋๋ค. Pub/Sub๋ ์ข ์ข ๋ชจ๋ ๋ฉ์์ง๊ฐ ์ต์ ํ ๋ฒ์ ๊ตฌ๋ ์์๊ฒ ์ ์ก๋๋๋ก ๋ฉ์์ง๋ฅผ ๋ ๋ฒ ์ด์ ์ ๋ฌํฉ๋๋ค.
๋ค์ ์ํ์ ์คํํ๊ธฐ ์ ์ ์ฃผ์ ์ฒ๋ฆฌ๋ฅผ ์ญ์ ํ๊ณ ์ฝ๋์ ํ์๋ ํ์ ๊ฐ์ ์ฑ์์ผ ํฉ๋๋ค. ์ด๋ ์ด์ ์ ๋ง๋ ํ๋ก์ ํธ ๋ฐ Pub/Sub ๋ฆฌ์์ค์ ์ํ์ ์ฐ๊ฒฐํ๋ ๋ฐ ํ์ํฉ๋๋ค.
๊ตฌ๋
ID์ my-sub
๋ฅผ ์ฌ์ฉํฉ๋๋ค.
๋ฉ์์ง๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ๋ณด์ฌ์ฃผ๋ ๋ ๋ง์ ์์๋ ํด๋ผ์ด์ธํธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ฝ๋ ์ํ์ ์ฐธ์กฐํ์ธ์.
Python
C++
C#
Go
Java
Node.js
PHP
Ruby