Google Cloud Pub/Subとの連携¶
Google Cloud PlatformのプロダクトであるGoogle Cloud Pub/Subへ、通信モジュールからのデータを送信することを可能にします。
ヒント
Google Cloud Pub/Sub についての詳しい情報は 公式ドキュメント を参照してください。
設定の概要について¶
- Google Cloud Platformのサービスアカウントを作成し、秘密鍵を含むJSONをsakura.ioへ登録する必要があります
- sakura.ioからGoogle Cloud
Pub/SubへPublishする際に利用するTopicを作成しておく必要があります
- 上記のサービスアカウントに対して、このTopicへのPublishを行うための権限を付与する必要があります
- TopicへPublishされたデータを、お客様の作成した受け口に渡すためのSubscriptionを作成しておく必要があります
事前準備¶
認証用のJSON作成方法¶
Google Cloud Platform上でPublishを行う為に、サービスアカウントに紐付いたJSON形式のサービスアカウントキーを取得します。
Google Cloud Platformのコンソール画面より、「IAMと管理」→「サービスアカウント」をクリックします。

「サービスアカウントを作成」をクリックします。

「サービスアカウント名」に任意の文字列を入れ、作成を選択します。 (権限は後ほどTopicごとに設定するため、ここでは役割を指定する必要はありません。)

サービスアカウント作成後、「オプション」から「キーを作成」をクリックします。

「キーのタイプ」がJSON
であることを確認した上で「作成」を押し、JSON形式のサービスアカウントキーをダウンロードします。

Topicの作成と権限の設定¶
sakura.ioからのメッセージを受けるためのTopicを作成します。 Google Cloud Pub/Subを開きます。

初めて開いた場合には、APIを有効化する必要があります。

Topic の作成を行います。

Topic名は任意のものを入力し、作成します。

作成したTopicの権限設定を開きます。

メンバーとして、上で作成したサービスアカウント名を入力し、権限として
Pub/Sub パブリッシャー
を選択し、追加をクリックします。

Subscriptionの作成¶
Topicから配信されたメッセージを外部から取得するためには Subscription を作成する必要があります。
注意事項
「サブスクライバ(Subscriber)」と「サブスクリプション(Subscription)」は混同しやすいので注意してください。 Subscriberはお客様側で用意していただくメッセージ受信機能、SubscriptionはTopicからSubscriberへメッセージを渡すためのGoogle Cloud Pub/Subにある機構です。
Topic作成後、Pub/Subの サブスクリプション から サブスクリプションを作成
をクリックします。

サブスクリプションID
に任意の文字列を入れ、 Cloud Pub/Sub トピック
は上で作成したトピック名を、 配信タイプ
は pull
を選択します。
(既にpush配信用のSubscriberを用意しているなら、配信タイプに push
を選択してください)

画面下部の CREATE
をクリックするとSubscriptionが作成されます。
コントロールパネルの操作方法¶
Google Cloud Pub/Subの連携サービス追加¶
連携サービスの追加を行いたいプロジェクトの 詳細
ボタンをクリックします。

プロジェクトの詳細ページ内の 連携サービス
をクリックします。連携サービス一覧表示に切り替わるので、右端の 連携サービス追加
をクリックします。

連携サービスの選択画面でGoogle Cloud Pub/Sub Publisher
をクリックします。

以下の項目を入力し、作成
ボタンをクリックします。
名前:任意のサービス連携名
Publish先のTopic名:上記で設定したGoogle Cloud Pub/Sub上のTopic名
サービスアカウントキー (JSON形式):Google Cloud Platform上で作成したJSON形式のサービスアカウントキー

注意事項
連携サービス作成、更新を行う際、正しい認証用JSONであるか、必要な権限が付与されているかの検証のために、以下のようなメッセージを送信します。
{"type": "keepalive", "datetime": "2017-12-12T08:46:12.158281Z"}