DartでMomento Topicsを始める
DartとMomentoトピックをすぐに使い始める必要がある場合、このページには必要な基本的なAPIコールが含まれています。Dart SDK のサンプル を参照してください。
Install the Momento SDK
Momento Dart SDKはpub.dev as momentoで入手可能です。
Dartプログラムにインストールするには、以下を使用します:
dart pub add momento
Flutterプログラムにインストールするには、次のようにします:
flutter pub add momento
Momento APIキーを取得する
Momento APIキーが必要です。Momento Web Console](https://console.gomomento.com/)から取得できます。 トークンを取得したら、Momentoクライアントが利用できるように環境変数に保存します:
export MOMENTO_API_KEY=<your api key here>
Note: セキュリティ強化のためには、APIキーを環境変数ではなく、AWS Secret ManagerやGCP Secret Managerのようなものに入れるのがベストプラクティスだが、ここではデモのためにAPIキーを使っている。
TopicClientのセットアップ
このコードでは、パブ/サブ・トピックとの対話に使用する TopicClient を作成します。
try {
final topicClient = TopicClient(
CredentialProvider.fromEnvironmentVariablesV2(),
TopicClientConfigurations.latest());
} catch (e) {
print("Unable to create topic client: $e");
exit(1);
}