12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

gcloud ツールで Pub/Sub を行う

Last updated at Posted at 2018-02-07

GCP の gcloud ツールで Pub/Sub を行います。

gcloud init で configuration の作成が終っているものとします。

$ gcloud init
Welcome! This command will take you through the configuration of gcloud.

Settings from your current configuration [default] are:
core:
  account: abcde@gmail.com
  disable_usage_reporting: 'True'
  project: my-project-sep-10-2017

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings 
 [2] Create a new configuration
Please enter your numeric choice:

topic_1 というトピックを作成します。

$ gcloud pubsub topics create topic_1
Created topic [projects/my-project-aug-29-2016/topics/topic_1].

subscription_1 というサブスクリプションを作成します。

$ gcloud pubsub subscriptions create --topic topic_1 subscription_1
Created subscription [projects/my-project-aug-29-2016/subscriptions/subscription_1].

topic_1 に メッセージを publish します。

$ gcloud pubsub topics publish topic_1  --message "Good Morning"
messageIds:
- '33129870297757'

subscription_1 からメッセージを取ります。

```text
$ gcloud pubsub subscriptions pull --auto-ack subscription_1
┌──────────────┬────────────────┬────────────┐
│     DATA     │   MESSAGE_ID   │ ATTRIBUTES │
├──────────────┼────────────────┼────────────┤
│ Good Morning │ 33129870297757 │            │
└──────────────┴────────────────┴────────────┘

別のメッセージを topic_1 に送ります。

$ gcloud pubsub topics publish topic_1  --message "Hello World!"
messageIds:
- '33123573760843'

subscription_1 からメッセージを取ります。

$ gcloud pubsub subscriptions pull --auto-ack subscription_1
┌──────────────┬────────────────┬────────────┐
│     DATA     │   MESSAGE_ID   │ ATTRIBUTES │
├──────────────┼────────────────┼────────────┤
│ Hello World! │ 33123573760843 │            │
└──────────────┴────────────────┴────────────┘

トピックの一覧

gcloud pubsub topics list

topic_1 のサブスクリプションの表示

gcloud pubsub topics list-subscriptions topic_1

サブスクリプションの一覧

gcloud pubsub subscriptions list

トピック と サブスクリプションを GUI で確認することもできます。
gcloud_pubsub_feb0701.png

トピック (topic_1) の削除

gcloud pubsub topics delete topic_1

サブスクリプション (subscription_1) の削除

gcloud pubsub subscriptions delete subscription_1
12
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?