Google Cloud Pub/Sub アダプター
仕組み
このアダプターは、Google Cloud Pub/Sub サービスを使用して、Socket.IO クラスタのノード間でメッセージを転送します。
このアダプターのソースコードはこちらにあります。
サポートされている機能
機能 | socket.io バージョン | サポート |
---|---|---|
ソケット管理 | 4.0.0 | ✅ はい (バージョン 0.1.0 以降) |
サーバー間通信 | 4.1.0 | ✅ はい (バージョン 0.1.0 以降) |
確認応答付きブロードキャスト | 4.5.0 | ✅ はい (バージョン 0.1.0 以降) |
接続状態の回復 | 4.6.0 | ❌ いいえ |
インストール
npm install @socket.io/gcp-pubsub-adapter
使用方法
import { PubSub } from "@google-cloud/pubsub";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/gcp-pubsub-adapter";
const pubsub = new PubSub({
projectId: "your-project-id"
});
const topic = pubsub.topic(topicNameOrId);
const io = new Server({
adapter: createAdapter(topic)
});
// wait for the creation of the pub/sub subscription
await io.of("/").adapter.init();
io.listen(3000);
オプション
名前 | 説明 | デフォルト値 |
---|---|---|
subscriptionPrefix | 作成する新しいサブスクリプションのプレフィックス。 | socket.io |
subscriptionOptions | サブスクリプションの作成に使用されるオプション。 | - |
heartbeatInterval | 2つのハートビート間のミリ秒数。 | 5_000 |
heartbeatTimeout | ハートビートがない状態でノードがダウンしているとみなすまでのミリ秒数。 | 10_000 |
最新のリリース
バージョン | リリース日 | リリースノート | 差分 |
---|---|---|---|
0.1.0 | 2024年3月 | リンク | - |