GS2-Distributor Deploy/CDK リファレンス

GS2-Deployのスタックを作成する際に使用するテンプレートのフォーマットと、CDKによる各種言語のテンプレート出力の実装例

エンティティ

Deploy処理で操作する対象リソース

Namespace

ネームスペース

ネームスペースは一つのプロジェクトで同じサービスを異なる用途で複数利用できるようにするための仕組みです。
GS2 の各サービスはネームスペース単位で管理されます。ネームスペースが異なれば、同じサービスでも完全に独立したデータ空間として扱われます。

そのため、各サービスの利用を開始するにあたってネームスペースを作成する必要があります。

Request

リソースの生成リクエスト

有効化条件必須デフォルト値の制限説明
namestring
~ 128文字ネームスペース名
ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
descriptionstring~ 1024文字説明文
transactionSettingTransactionSettingトランザクション設定
assumeUserIdstring~ 1024文字GS2-Identifier ユーザーGRN
autoRunStampSheetNotificationNotificationSetting
トランザクションの自動実行が完了したときのプッシュ通知(旧仕様)
autoRunTransactionNotificationNotificationSetting
トランザクションの自動実行が完了したときのプッシュ通知
logSettingLogSettingログの出力設定

GetAttr

!GetAttrタグで取得可能なリソースの生成結果

説明
ItemNamespace作成したネームスペース

実装例

Type: GS2::Distributor::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSetting: null
  AssumeUserId: grn:gs2::YourOwnerId:identifier:user:user-0001
  AutoRunStampSheetNotification: null
  AutoRunTransactionNotification: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/distributor"
    "github.com/openlyinc/pointy"
)

SampleStack := core.NewStack()
distributor.NewNamespace(
    &SampleStack,
    "namespace-0001",
    distributor.NamespaceOptions{
        AssumeUserId: pointy.String("grn:gs2::YourOwnerId:identifier:user:user-0001"),
        LogSetting: &core.LogSetting{
            LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
        },
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Distributor\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Distributor\Model\Options\NamespaceOptions(
                assumeUserId: "grn:gs2::YourOwnerId:identifier:user:user-0001",
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.distributor.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.distributor.model.options.NamespaceOptions()
                        .withAssumeUserId("grn:gs2::YourOwnerId:identifier:user:user-0001")
                        .withLogSetting(new io.gs2.cdk.core.model.LogSetting(
                            "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                        ))
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Distributor.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Distributor.Model.Options.NamespaceOptions
            {
                assumeUserId = "grn:gs2::YourOwnerId:identifier:user:user-0001",
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import distributor from "@/gs2cdk/distributor";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new distributor.model.Namespace(
            this,
            "namespace-0001",
            {
                assumeUserId: "grn:gs2::YourOwnerId:identifier:user:user-0001",
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, distributor

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        distributor.Namespace(
            stack=self,
            name='namespace-0001',
            options=distributor.NamespaceOptions(
                assume_user_id='grn:gs2::YourOwnerId:identifier:user:user-0001',
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template

TransactionSetting

トランザクション設定

トランザクション設定は、トランザクションの実行方法・整合性・非同期処理・競合回避の仕組みを制御する設定です。
自動実行(AutoRun)、アトミック実行(AtomicCommit)、GS2-Distributor を利用した非同期実行、スクリプト結果の一括適用、GS2-JobQueue による入手アクションの非同期化などを組み合わせ、ゲームロジックに応じた堅牢なトランザクション管理を可能にします。

有効化条件必須デフォルト値の制限説明
enableAutoRunbool
false発行したトランザクションをサーバーサイドで自動的に実行するか
enableAtomicCommitbool{enableAutoRun} == true
✓*
falseトランザクションの実行をアトミックにコミットするか
※ enableAutoRun が true であれば 必須
transactionUseDistributorbool{enableAtomicCommit} == true
✓*
falseトランザクションを非同期処理で実行する
※ enableAtomicCommit が true であれば 必須
commitScriptResultInUseDistributorbool{transactionUseDistributor} == true
✓*
falseスクリプトの結果コミット処理を非同期処理で実行するか
※ transactionUseDistributor が true であれば 必須
acquireActionUseJobQueuebool{enableAtomicCommit} == true
✓*
false入手アクションを実行する際に GS2-JobQueue を使用するか
※ enableAtomicCommit が true であれば 必須
distributorNamespaceIdstring
“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024文字トランザクションの実行に使用する GS2-Distributor ネームスペース GRN
queueNamespaceIdstring
“grn:gs2:{region}:{ownerId}:queue:default”~ 1024文字トランザクションの実行に使用する GS2-JobQueue のネームスペース GRN

NotificationSetting

プッシュ通知に関する設定

GS2 のマイクロサービス内で何らかのイベントが発生した際に、プッシュ通知を送信するための設定です。
ここでいうプッシュ通知は GS2-Gateway の提供する WebSocket インターフェースを経由した処理であり、スマートフォンのプッシュ通知とは性質が異なります。
たとえば、マッチメイキングが完了した時やフレンドリクエストが届いた時など、ゲームクライアントの操作とは関係なく状態が変化した際に GS2-Gateway を経由してプッシュ通知をすることで、ゲームクライアントは状態の変化を検知することができます。

GS2-Gateway のプッシュ通知は通知先のデバイスがオフラインだった時に追加の処理としてモバイルプッシュ通知を送信できます。
モバイルプッシュ通知をうまく利用すれば、マッチメイキング中にゲームを終了しても、モバイルプッシュ通知を使用してプレイヤーに通知し、ゲームに戻ってくるフローを実現できる可能性があります。

有効化条件必須デフォルト値の制限説明
gatewayNamespaceIdstring
“grn:gs2:{region}:{ownerId}:gateway:default”~ 1024文字プッシュ通知に使用する GS2-Gateway のネームスペース
「grn:gs2:」から始まる GRN 形式で GS2-Gateway のネームスペースIDを指定します。
enableTransferMobileNotificationbool?falseモバイルプッシュ通知へ転送するか
この通知を送信しようとした時、通知先のデバイスがオフラインだった場合、モバイルプッシュ通知へ転送するかどうかを指定します。
soundstring{enableTransferMobileNotification} == true~ 1024文字モバイルプッシュ通知で使用するサウンドファイル名
ここで指定したサウンドファイル名は、モバイルプッシュ通知を送信する際に使用され、特別なサウンドで通知を出すことができます。

※ enableTransferMobileNotification が true であれば 有効
enable文字列列挙型
enum {
  “Enabled”,
  “Disabled”
}
“Enabled”プッシュ通知を有効にするか
定義説明
“Enabled”有効
“Disabled”無効

LogSetting

ログの書き出し設定

ログデータの書き出し設定を管理します。この型は、ログデータを書き出すために使用されるログ名前空間の識別子(Namespace ID)を保持します。
ログ名前空間IDは、ログデータを集約し、保存する対象の GS2-Log の名前空間を指定します。
この設定を通じて、この名前空間以下のAPIリクエスト・レスポンスログデータが対象の GS2-Log へ出力されるようになります。
GS2-Log にはリアルタイムでログが提供され、システムの監視や分析、デバッグなどに利用できます。

有効化条件必須デフォルト値の制限説明
loggingNamespaceIdstring
~ 1024文字ログを出力する GS2-Log のネームスペース GRN
「grn:gs2:」ではじまる GRN 形式のIDで指定する必要があります。

CurrentDistributorMaster

現在アクティブなマスターデータ

現在ネームスペース内で有効な、配信モデルの定義を記述したマスターデータです。
GS2ではマスターデータの管理にJSON形式のファイルを使用します。
ファイルをアップロードすることで、実際にサーバーに設定を反映することができます。

JSONファイルを作成する方法として、マネージメントコンソール内にマスターデータエディタを提供しています。
また、よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。

Request

リソースの生成リクエスト

有効化条件必須デフォルト値の制限説明
namespaceNamestring
~ 128文字ネームスペース名
ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
mode文字列列挙型
enum {
  “direct”,
  “preUpload”
}
“direct”更新モード
定義説明
“direct”マスターデータを直接更新
“preUpload”マスターデータをアップロードしてから更新
settingsstring{mode} == “direct”
✓*
~ 5242880文字マスターデータ
※ mode が “direct” であれば必須
uploadTokenstring{mode} == “preUpload”
✓*
~ 1024文字プレアップロードで取得したトークン
※ mode が “preUpload” であれば必須

GetAttr

!GetAttrタグで取得可能なリソースの生成結果

説明
ItemCurrentDistributorMaster更新した現在アクティブな配信モデルのマスターデータ

実装例

Type: GS2::Distributor::CurrentDistributorMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-03-01",
    "distributorModels": [
      {
        "name": "basic",
        "metadata": "BASIC",
        "inboxNamespaceId": "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
      },
      {
        "name": "special",
        "metadata": "SPECIAL",
        "inboxNamespaceId": "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
        "whiteListTargetIds": [
          "test"
        ]
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/distributor"
    "github.com/openlyinc/pointy"
)

SampleStack := core.NewStack()
distributor.NewNamespace(
    &SampleStack,
    "namespace-0001",
    distributor.NamespaceOptions{},
).MasterData(
    []distributor.DistributorModel{
        distributor.NewDistributorModel(
            "basic",
            distributor.DistributorModelOptions{
                Metadata: pointy.String("BASIC"),
                InboxNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"),
            },
        ),
        distributor.NewDistributorModel(
            "special",
            distributor.DistributorModelOptions{
                Metadata: pointy.String("SPECIAL"),
                InboxNamespaceId: pointy.String("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"),
                WhiteListTargetIds: []string{
                    "test",
                },
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Distributor\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Distributor\Model\DistributorModel(
                    name:"basic",
                    options: new \Gs2Cdk\Distributor\Model\Options\DistributorModelOptions(
                        metadata:"BASIC",
                        inboxNamespaceId:"grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    )
                ),
                new \Gs2Cdk\Distributor\Model\DistributorModel(
                    name:"special",
                    options: new \Gs2Cdk\Distributor\Model\Options\DistributorModelOptions(
                        metadata:"SPECIAL",
                        inboxNamespaceId:"grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds:[
                            "test",
                        ]
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.distributor.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.distributor.model.DistributorModel(
                    "basic",
                    new io.gs2.cdk.distributor.model.options.DistributorModelOptions()
                        .withMetadata("BASIC")
                        .withInboxNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001")
                ),
                new io.gs2.cdk.distributor.model.DistributorModel(
                    "special",
                    new io.gs2.cdk.distributor.model.options.DistributorModelOptions()
                        .withMetadata("SPECIAL")
                        .withInboxNamespaceId("grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001")
                        .withWhiteListTargetIds(Arrays.asList(
                            "test"
                        ))
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Distributor.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Distributor.Model.DistributorModel[] {
                new Gs2Cdk.Gs2Distributor.Model.DistributorModel(
                    name: "basic",
                    options: new Gs2Cdk.Gs2Distributor.Model.Options.DistributorModelOptions
                    {
                        metadata = "BASIC",
                        inboxNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    }
                ),
                new Gs2Cdk.Gs2Distributor.Model.DistributorModel(
                    name: "special",
                    options: new Gs2Cdk.Gs2Distributor.Model.Options.DistributorModelOptions
                    {
                        metadata = "SPECIAL",
                        inboxNamespaceId = "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds = new string[]
                        {
                            "test"
                        }
                    }
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import distributor from "@/gs2cdk/distributor";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new distributor.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new distributor.model.DistributorModel(
                    "basic",
                    {
                        metadata: "BASIC",
                        inboxNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001"
                    }
                ),
                new distributor.model.DistributorModel(
                    "special",
                    {
                        metadata: "SPECIAL",
                        inboxNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001",
                        whiteListTargetIds: [
                            "test",
                        ]
                    }
                )
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, distributor

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        distributor.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            distributor_models=[
                distributor.DistributorModel(
                    name='basic',
                    options=distributor.DistributorModelOptions(
                        metadata = 'BASIC',
                        inbox_namespace_id = 'grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001'
                    ),
                ),
                distributor.DistributorModel(
                    name='special',
                    options=distributor.DistributorModelOptions(
                        metadata = 'SPECIAL',
                        inbox_namespace_id = 'grn:gs2:ap-northeast-1:YourOwnerId:inbox:inbox-0001',
                        white_list_target_ids = [
                            'test',
                        ]
                    ),
                ),
            ],
        )

print(SampleStack().yaml())  # Generate Template

DistributorModel

配信モデル

配信モデルとはエンティティの入手時に所持枠を超えて入手した時のポリシーを設定するエンティティです。
GS2-Distributor を通して入手処理を行うことで、あふれたリソースを GS2-Inbox のメッセージとして転送することができます。

有効化条件必須デフォルト値の制限説明
distributorModelIdstring
✓*
~ 1024文字配信モデル GRN
※ サーバー側で自動的に設定
namestring
~ 128文字配信モデル名
配信モデル固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。
metadatastring~ 2048文字メタデータ
メタデータには任意の値を設定できます。
これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。
inboxNamespaceIdstring~ 1024文字あふれたリソースを転送する GS2-Inbox のネームスペース GRN
whiteListTargetIdsList<string>[]0 ~ 1000 itemsGS2-Distributorを通して処理出来る対象のリソースGRNのホワイトリスト
この配信モデルを使用して入手処理を行える対象となるリソースのGRNプレフィックスを指定します。