> For the complete documentation index, see [llms.txt](/llms.txt)

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

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




## エンティティ

Deploy処理で操作の対象となるリソース

### Namespace

ネームスペース<br>

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

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

#### Request

リソースの生成・更新リクエスト

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| description | string |  | |  |  ~ 1024文字 | 説明文 |
| transactionSetting | [TransactionSetting](#transactionsetting) |  | |  |  | トランザクション設定<br>リソース配布処理時の分散トランザクションの実行方法を制御する設定です。自動実行、アトミックコミット、非同期処理などのオプションをサポートします。 |
| assumeUserId | string |  | |  |  ~ 1024文字 | GS2-Identifier ユーザーGRN |
| autoRunStampSheetNotification | [NotificationSetting](#notificationsetting) |  | ✓|  |  | トランザクションの自動実行が完了したときのプッシュ通知(旧仕様)<br>トランザクションがサーバーサイドで自動実行完了した際に GS2-Gateway 経由でプッシュ通知を送信するための設定です。これは旧仕様であり、新仕様では autoRunTransactionNotification を使用してください。 |
| autoRunTransactionNotification | [NotificationSetting](#notificationsetting) |  | ✓|  |  | トランザクションの自動実行が完了したときのプッシュ通知<br>分散トランザクションがサーバーサイドで自動実行完了した際に GS2-Gateway 経由でプッシュ通知を送信するための設定です。トランザクション結果をクライアントに通知し、ローカル状態を適切に更新できるようにします。 |
| logSetting | [LogSetting](#logsetting) |  | |  |  | ログの出力設定<br>ディストリビューター操作のログデータを GS2-Log に出力するための設定です。GS2-Log のネームスペースを指定することで、リソース配布・入手アクション実行・トランザクション処理の API リクエスト・レスポンスログを収集できます。 |

#### GetAttr

[!GetAttr](/articles/tech/deploy/#getattr)タグで取得可能なリソースの生成結果

| | 型 | 説明 |
| --- | --- | --- |
| Item | [Namespace](../sdk#namespace) | 作成したネームスペース

#### 実装例




**GS2-Deploy(YAML)**
```yaml

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

```

**Go**
```go

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

```

**PHP**
```php

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

```

**Java**
```java

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

```

**C#**
```csharp

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

```

**TypeScript**
```typescript

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

```

**Python**
```python

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

トランザクション設定<br>

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

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

#### NotificationSetting

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

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

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

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

#### LogSetting

ログの出力設定<br>

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

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

---

### CurrentDistributorMaster

現在アクティブな配信モデルのマスターデータ<br>

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

JSONファイルを作成する方法として、マネージメントコンソール内にマスターデータエディタを提供しています。<br>
また、よりゲームの運営に相応しいツールを作成し、適切なフォーマットのJSONファイルを書き出すことでもサービスを利用可能です。
{{% alert title="Note" color="info" %}}
JSONファイルの形式については [GS2-Distributor マスターデータリファレンス](api_reference/distributor/master_data/) をご参照ください。
{{% /alert %}}

#### Request

リソースの生成・更新リクエスト

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| namespaceName | string |  | ✓|  |  ~ 128文字 | ネームスペース名<br>ネームスペース固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| mode | 文字列列挙型<br>enum {<br>"direct",<br>"preUpload"<br>}<br> |  | | "direct" |  | 更新モード"direct": マスターデータを直接更新 / "preUpload": マスターデータをアップロードしてから更新 /  |
| settings | string | {mode} == "direct" | ✓※|  |  ~ 5242880 バイト (5MB) | マスターデータ<br>※ mode が "direct" であれば必須 |
| uploadToken | string | {mode} == "preUpload" | ✓※|  |  ~ 1024文字 | 事前アップロードで取得したトークン<br>アップロードしたマスターデータを適用するために使用されます。<br>※ mode が "preUpload" であれば必須 |

#### GetAttr

[!GetAttr](/articles/tech/deploy/#getattr)タグで取得可能なリソースの生成結果

| | 型 | 説明 |
| --- | --- | --- |
| Item | [CurrentDistributorMaster](../sdk#currentdistributormaster) | 更新された現在アクティブな配信モデルのマスターデータ

#### 実装例




**GS2-Deploy(YAML)**
```yaml

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

```

**Go**
```go

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

```

**PHP**
```php

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

```

**Java**
```java

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

```

**C#**
```csharp

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

```

**TypeScript**
```typescript

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

```

**Python**
```python

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

配信モデル<br>

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

|  | 型 | 有効化条件 | 必須 | デフォルト | 値の制限 | 説明 |
| --- | --- | --- | --- | --- | --- | --- |
| distributorModelId | string |  | ※ |  |  ~ 1024文字 | 配信モデルGRN<br>※ サーバーが自動で設定 |
| name | string |  | ✓ |  |  ~ 128文字 | 配信モデル名<br>配信モデル固有の名前。英数字および -(ハイフン) _(アンダースコア) .(ピリオド)で指定します。 |
| metadata | string |  |  |  |  ~ 2048文字 | メタデータ<br>メタデータには任意の値を設定できます。<br>これらの値は GS2 の動作には影響しないため、ゲーム内で利用する情報の保存先として使用できます。 |
| inboxNamespaceId | string |  |  |  |  ~ 1024文字 | あふれたリソースを転送する GS2-Inbox のネームスペースGRN<br>リソースの入手がプレイヤーの所持枠を超えた場合、あふれたリソースは指定された GS2-Inbox ネームスペースにメッセージとして転送されます。プレイヤーは後から受信箱からリソースを受け取ることができます。 |
| whiteListTargetIds | List&lt;string&gt; |  |  | [] | 0 ~ 1000 items | GS2-Distributorを通して処理出来る対象のリソースGRNのホワイトリスト<br>この配信モデルを使用して入手処理を行える対象となるリソースのGRNプレフィックスを指定します。 |

---



