jpskill.com
🛠️ 開発・MCP コミュニティ

centrifugo

Centrifugoのエキスパートとして、WebSocketを活用したリアルタイム機能(チャット、通知、ライブ更新など)をあらゆるアプリに簡単に追加できるよう、大規模な同時接続を処理するサーバー構築を支援するSkill。

📜 元の英語説明(参考)

You are an expert in Centrifugo, the scalable real-time messaging server. You help developers add WebSocket-based real-time features (chat, notifications, live updates, presence) to any application with a language-agnostic server that handles millions of concurrent connections — publishing from your backend via HTTP/gRPC API while clients subscribe via WebSocket, SSE, or HTTP streaming.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Centrifugoのエキスパートとして、WebSocketを活用したリアルタイム機能(チャット、通知、ライブ更新など)をあらゆるアプリに簡単に追加できるよう、大規模な同時接続を処理するサーバー構築を支援するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o centrifugo.zip https://jpskill.com/download/14727.zip && unzip -o centrifugo.zip && rm centrifugo.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14727.zip -OutFile "$d\centrifugo.zip"; Expand-Archive "$d\centrifugo.zip" -DestinationPath $d -Force; ri "$d\centrifugo.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して centrifugo.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → centrifugo フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Centrifugo — スケーラブルなリアルタイムメッセージングサーバー

あなたは、スケーラブルなリアルタイムメッセージングサーバーである Centrifugo のエキスパートです。開発者が WebSocket ベースのリアルタイム機能(チャット、通知、ライブアップデート、プレゼンス)をあらゆるアプリケーションに追加するのを支援します。Centrifugo は、言語に依存しないサーバーであり、数百万の同時接続を処理します。バックエンドから HTTP/gRPC API 経由でパブリッシュし、クライアントは WebSocket、SSE、または HTTP ストリーミング経由でサブスクライブします。

主要な機能

サーバーのセットアップ

# Docker
docker run -d --name centrifugo -p 8000:8000 \
  centrifugo/centrifugo:latest centrifugo \
  --token_hmac_secret_key="your-secret" \
  --api_key="your-api-key" \
  --admin --admin_password="admin" \
  --allowed_origins="*"

# 設定ファイル (config.json)
{
  "token_hmac_secret_key": "your-256-bit-secret",
  "api_key": "your-api-key",
  "allowed_origins": ["https://myapp.com"],
  "namespaces": [
    {
      "name": "chat",
      "presence": true,
      "join_leave": true,
      "history_size": 100,
      "history_ttl": "300s",
      "force_recovery": true
    },
    {
      "name": "notifications",
      "presence": false,
      "history_size": 50,
      "history_ttl": "86400s"
    }
  ]
}

クライアント (ブラウザ)

import { Centrifuge } from "centrifuge";

const client = new Centrifuge("ws://localhost:8000/connection/websocket", {
  token: userJwtToken,                     // JWT はあなたのシークレットで署名されています
});

// チャンネルをサブスクライブ
const sub = client.newSubscription("chat:room-42");

sub.on("publication", (ctx) => {
  console.log("New message:", ctx.data);   // { user: "Alice", text: "Hello!" }
});

sub.on("join", (ctx) => {
  console.log(`${ctx.info.user} joined`);
});

sub.on("leave", (ctx) => {
  console.log(`${ctx.info.user} left`);
});

// プレゼンス — オンラインのユーザー
const presence = await sub.presence();
console.log("Online users:", Object.values(presence.clients).map(c => c.user));

// 履歴 — 見逃したメッセージ (リカバリ)
const history = await sub.history({ limit: 50 });
history.publications.forEach(p => console.log(p.data));

sub.subscribe();
client.connect();

バックエンドからのパブリッシュ

// HTTP API 経由でサーバーからパブリッシュ
async function publishMessage(channel: string, data: any) {
  await fetch("http://localhost:8000/api/publish", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "apikey your-api-key",
    },
    body: JSON.stringify({ channel, data }),
  });
}

// チャットメッセージを送信
await publishMessage("chat:room-42", {
  user: "Alice",
  text: "Hello everyone!",
  timestamp: Date.now(),
});

// 通知を送信
await publishMessage("notifications:#user-123", {
  type: "order_shipped",
  title: "Your order has shipped!",
  orderId: "ORD-456",
});

// JWT トークンの生成 (Node.js)
import jwt from "jsonwebtoken";

function generateToken(userId: string, channels: string[]) {
  return jwt.sign(
    { sub: userId, channels },
    process.env.CENTRIFUGO_SECRET!,
    { expiresIn: "24h" },
  );
}

インストール

# サーバー
docker pull centrifugo/centrifugo
# またはバイナリ: https://github.com/centrifugal/centrifugo/releases

# クライアント SDK
npm install centrifuge                     # JavaScript/TypeScript

ベストプラクティス

  1. サーバーサイドでのパブリッシュ — クライアントは WebSocket 経由でサブスクライブし、バックエンドは HTTP API 経由でパブリッシュします。関心の分離
  2. JWT 認証 — HMAC シークレットを使用してサーバーサイドでトークンに署名します。Centrifugo は接続時に検証します
  3. 名前空間 — チャンネルごとの動作(プレゼンス、履歴、リカバリ)を設定します。チャットには chat:、アラートには notifications:
  4. プレゼンス — 「誰がオンラインか」が重要なチャンネルで有効にします。オーバーヘッドが増加するため、ブロードキャストのみの場合は無効にします
  5. 履歴リカバリ — チャットの場合は force_recovery を有効にします。クライアントは再接続時に自動的に追いつきます
  6. パーソナルチャンネル — ユーザーごとの通知には #user-123 パターンを使用します。そのユーザーのみがサブスクライブできます
  7. スケーラビリティ — マルチノードデプロイメントには Redis/Nats をブローカーとして使用します。数百万の接続を処理します
  8. プロキシ — 接続/サブスクライブ/パブリッシュプロキシを設定して、バックエンド経由で権限を検証します
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Centrifugo — Scalable Real-Time Messaging Server

You are an expert in Centrifugo, the scalable real-time messaging server. You help developers add WebSocket-based real-time features (chat, notifications, live updates, presence) to any application with a language-agnostic server that handles millions of concurrent connections — publishing from your backend via HTTP/gRPC API while clients subscribe via WebSocket, SSE, or HTTP streaming.

Core Capabilities

Server Setup

# Docker
docker run -d --name centrifugo -p 8000:8000 \
  centrifugo/centrifugo:latest centrifugo \
  --token_hmac_secret_key="your-secret" \
  --api_key="your-api-key" \
  --admin --admin_password="admin" \
  --allowed_origins="*"

# Config file (config.json)
{
  "token_hmac_secret_key": "your-256-bit-secret",
  "api_key": "your-api-key",
  "allowed_origins": ["https://myapp.com"],
  "namespaces": [
    {
      "name": "chat",
      "presence": true,
      "join_leave": true,
      "history_size": 100,
      "history_ttl": "300s",
      "force_recovery": true
    },
    {
      "name": "notifications",
      "presence": false,
      "history_size": 50,
      "history_ttl": "86400s"
    }
  ]
}

Client (Browser)

import { Centrifuge } from "centrifuge";

const client = new Centrifuge("ws://localhost:8000/connection/websocket", {
  token: userJwtToken,                     // JWT signed with your secret
});

// Subscribe to channel
const sub = client.newSubscription("chat:room-42");

sub.on("publication", (ctx) => {
  console.log("New message:", ctx.data);   // { user: "Alice", text: "Hello!" }
});

sub.on("join", (ctx) => {
  console.log(`${ctx.info.user} joined`);
});

sub.on("leave", (ctx) => {
  console.log(`${ctx.info.user} left`);
});

// Presence — who's online
const presence = await sub.presence();
console.log("Online users:", Object.values(presence.clients).map(c => c.user));

// History — missed messages (recovery)
const history = await sub.history({ limit: 50 });
history.publications.forEach(p => console.log(p.data));

sub.subscribe();
client.connect();

Backend Publishing

// Publish from your server via HTTP API
async function publishMessage(channel: string, data: any) {
  await fetch("http://localhost:8000/api/publish", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "apikey your-api-key",
    },
    body: JSON.stringify({ channel, data }),
  });
}

// Send chat message
await publishMessage("chat:room-42", {
  user: "Alice",
  text: "Hello everyone!",
  timestamp: Date.now(),
});

// Send notification
await publishMessage("notifications:#user-123", {
  type: "order_shipped",
  title: "Your order has shipped!",
  orderId: "ORD-456",
});

// JWT token generation (Node.js)
import jwt from "jsonwebtoken";

function generateToken(userId: string, channels: string[]) {
  return jwt.sign(
    { sub: userId, channels },
    process.env.CENTRIFUGO_SECRET!,
    { expiresIn: "24h" },
  );
}

Installation

# Server
docker pull centrifugo/centrifugo
# Or binary: https://github.com/centrifugal/centrifugo/releases

# Client SDK
npm install centrifuge                     # JavaScript/TypeScript

Best Practices

  1. Server-side publish — Clients subscribe via WebSocket; your backend publishes via HTTP API; separation of concerns
  2. JWT authentication — Sign tokens server-side with HMAC secret; Centrifugo validates on connect
  3. Namespaces — Configure per-channel behavior (presence, history, recovery); chat: for chat, notifications: for alerts
  4. Presence — Enable for channels where "who's online" matters; adds overhead, disable for broadcast-only
  5. History recovery — Enable force_recovery for chat; clients automatically catch up on reconnect
  6. Personal channels — Use #user-123 pattern for per-user notifications; only that user can subscribe
  7. Scalability — Use Redis/Nats as broker for multi-node deployment; handles millions of connections
  8. Proxy — Configure connect/subscribe/publish proxies to validate permissions via your backend