LoginSignup
0
0

[Cloud Storage API(V2)] Javaでバケットの変更通知(通知サブスクリプション)を取得する

Posted at

Cloud Storage API V2(Java)を使用して、
Cloud Storageのバケットの変更通知(通知サブスクリプション)を取得する方法
についてご紹介します。

APIを利用する環境の準備から始める場合や、コードを実行する際は、
⧉[Cloud Storage API(V2)] JavaでCloud Storageを使う
を参照ください。

No 目次
1 変更通知リストを取得
1 スコープ
2 実行
3 レスポンスの内容
2 変更通知を取得
1 スコープ
2 実行
3 レスポンスの内容

1. 変更通知リストを取得

指定したバケットの変更通知リストを取得します。

1.1. スコープ

このAPIを実行するには、以下のいずれかのスコープを指定してください。

StorageScopes.CLOUD_PLATFORM
StorageScopes.CLOUD_PLATFORM_READ_ONLY
StorageScopes.DEVSTORAGE_FULL_CONTROL
StorageScopes.DEVSTORAGE_READ_ONLY
StorageScopes.DEVSTORAGE_READ_WRITE

⧉[Cloud Storage API(V2)] JavaでCloud Storageを使う(2.2 Storageインスタンスを取得)
でスコープを指定してください。

1.2. 実行

public static void main(String[] args) throws Exception{
    Storage storage = getStorage();
    Storage.Notifications notifications = storage.notifications();
    Storage.Notifications.List list = notifications.list("バケットID");
    
    Notifications res = list.execute();
    System.out.println(res);
}

1.2.1. HTTPリクエスト

GET: https://storage.googleapis.com/storage/v1/b/{バケットID}/notificationConfigs
が実行されます。

1.2.2. クエリパラメータ

クエリパラメータはありません。

1.3. レスポンスの内容

Notifications

メソッド 戻り値 説明
getKind String リソースの種類
固定文字列:"storage#notifications"
getItems List<Notification> 通知リスト

Notification

メソッド 戻り値 説明
getId String 通知ID
getKind String リソースの種類
固定文字列:"storage#notification"
getSelfLink String 通知の正規URL
getEtag String サブスクリプション通知のHTTPエンティティタグ
getEventTypes List<String> 通知のイベントタイプ
getObjectNamePrefix String 通知されるオブジェクト名のプレフィックス(接頭語)
getPayloadFormat String ペイロードの目的のコンテンツ
"JSON_API_V1"、"NONE"
getTopic String 通知サブスクリプションが発行するPub/Subトピック
getCustomAttributes Map<String,String> Pub/Subメッセージに添付する追加属性

通知のイベントタイプ

定義値 内容
OBJECT_FINALIZE 新しいオブジェクトがバケット内に正常に作成された
OBJECT_METADATA_UPDATE 既存のオブジェクトのメタデータが変更された
OBJECT_DELETE オブジェクトが完全に削除された
OBJECT_ARCHIVE 【バケットでオブジェクトのバージョニングが有効になっている場合のみ】

非現行バージョンになった
(オブジェクトのライブバージョンが明示的に非現行になったため、または同じ名前のオブジェクトのアップロードによって置き換えられたため)

2. 変更通知を取得

指定した変更通知のメタデータを取得します。

2.1. スコープ

このAPIを実行するには、以下のいずれかのスコープを指定してください。

StorageScopes.CLOUD_PLATFORM
StorageScopes.CLOUD_PLATFORM_READ_ONLY
StorageScopes.DEVSTORAGE_FULL_CONTROL
StorageScopes.DEVSTORAGE_READ_ONLY
StorageScopes.DEVSTORAGE_READ_WRITE

⧉[Cloud Storage API(V2)] JavaでCloud Storageを使う(2.2 Storageインスタンスを取得)
でスコープを指定してください。

2.2. 実行

通知IDは、NotificationのgetId()で取得できる値を使用します。

public static void main(String[] args) throws Exception{
    Storage storage = getStorage();
    Storage.Notifications notifications = storage.notifications();
    Storage.Notifications.Get get = notifications.get("バケットID","通知ID");
    
    Notification res = get.execute();
    System.out.println(res);
}

2.2.1. HTTPリクエスト

GET: https://storage.googleapis.com/storage/v1/b/{バケットID}/notificationConfigs/{通知ID}
が実行されます。

2.2.2. クエリパラメータ

クエリパラメータはありません。

2.3. レスポンスの内容

Notification

2.3. レスポンスの内容(Notification)と同じです。




おしまい。。

0
0
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
0
0