Skip to Content
FeaturesModulesCentrifugo WebSocketCLI Commands

Centrifugo CLI Commands

Django-CFG provides management commands for testing and debugging Centrifugo integration.

centrifugo_publish

Publish messages to Centrifugo channels for testing and debugging.

This command uses the Direct Centrifugo Client by default, bypassing the wrapper for faster publishing.

Basic Usage

python manage.py centrifugo_publish \ --channel "notifications:user:123" \ --message "Your order has been shipped!"

Arguments

ArgumentShortRequiredDescription
--channel-cYesCentrifugo channel name
--message-mNo*Simple text message to publish
--data-dNo*JSON data to publish
--direct-NoUse direct client (default: True)

Either --message or --data is required.

Channel Naming

Use : for namespace separation (not #):

✅ Good
ai_chat:workspace:UUID
notifications:user:123
events:dashboard
❌ Bad
ai_chat#workspace#UUID
notifications#user#123
Interpreted as user-limited channel

Examples

Test AI Chat

python manage.py centrifugo_publish \ -c "ai_chat:workspace:UUID" \ -d '{ "type": "message_chunk", "message_id": "test-123", "chunk": "Hello from CLI!", "timestamp": "2025-12-14T14:00:00Z" }'

Send Notification

python manage.py centrifugo_publish \ -c "notifications:user:456" \ -m "Your payment was successful!"

Trigger Dashboard Event

python manage.py centrifugo_publish \ -c "dashboard:workspace:UUID" \ -d '{ "type": "metric_update", "metric": "active_users", "value": 142 }'

Response

On success:

📡 Publishing to channel: ai_chat:workspace:12f827f2-93d4-4248-9acb-cbd0dfcb5698 📦 Data: { "type": "message", "text": "Hello!", "timestamp": "2025-12-14T14:39:18.749638+00:00" } ✅ Message published successfully! Message ID: dbc4149b-8518-43fd-ba69-33fe02e2031f Published: True

Error Handling

Unknown channel

This means no clients are subscribed to this channel. The message is published but has no recipients.

CommandError: Centrifugo API error: unknown channel (channel: test:channel)

Invalid JSON

Check your JSON syntax. Use single quotes around the JSON string in bash.

CommandError: Invalid JSON in --data: Expecting value: line 1 column 1

Use Cases

Testing Real-Time Features

Verify WebSocket connections receive messages correctly.

# Terminal 1: Subscribe to channel in browser # Terminal 2: Publish test message python manage.py centrifugo_publish -c "test:channel" -m "Hello WebSocket!"

Debugging AI Chat

Send test messages to AI chat channels without running the full AI pipeline.

python manage.py centrifugo_publish \ -c "ai_chat:workspace:UUID" \ -d '{"type":"message_chunk","chunk":"Debug message"}'

Load Testing

Script multiple publishes to test performance.

for i in {1..100}; do python manage.py centrifugo_publish \ -c "load:test" \ -d "{\"index\":$i,\"timestamp\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"}" done

Integration Testing

Automate message publishing in test suites.

# tests/test_websocket.py from django.core.management import call_command def test_websocket_message(): call_command( 'centrifugo_publish', channel='test:channel', data='{"type":"test"}' )

generate_centrifugo_clients

Generate type-safe client SDKs for Centrifugo WebSocket RPC.

See Client Generation for detailed documentation.

Quick Start

# Generate Python client python manage.py generate_centrifugo_clients --output ./clients --python # Generate TypeScript client python manage.py generate_centrifugo_clients -o ./clients --typescript # Generate all clients python manage.py generate_centrifugo_clients -o ./clients --all

Arguments

ArgumentShortDescription
--output-oOutput directory (default: ./openapi/centrifuge)
--python-Generate Python client
--typescript-Generate TypeScript client
--go-Generate Go client
--all-Generate all clients
--verbose-Verbose output

See Also

Last updated on