WebSocket Connection
Subscriptions require a WebSocket connection to the GraphQL endpoint:Events Subscription
Subscribe to Events
Receive real-time platform events (errors, warnings, info messages).emergency- System is unusablealert- Action must be taken immediatelycritical- Critical conditionserror- Error conditionswarning- Warning conditionsinformational- Informational messagesdebug- Debug-level messages
Controller Status Subscription
Subscribe to Meshery Controllers Status
Monitor Meshery Operator, MeshSync, and Broker status in real-time.OPERATOR- Meshery OperatorMESHSYNC- MeshSync discovery engineBROKER- NATS message broker
DEPLOYED- Successfully deployedNOTDEPLOYED- Not deployedDEPLOYING- Deployment in progressUNDEPLOYED- UndeployedENABLED- Enabled and runningRUNNING- RunningCONNECTED- ConnectedUNKNOWN- Unknown status
Performance Testing Subscription
Subscribe to Performance Profiles
Watch for changes to performance test profiles.Subscribe to Performance Results
Receive real-time performance test results for a specific profile.Configuration Subscription
Subscribe to Configuration Changes
Monitor changes to patterns (designs) and filters.Cluster Resources Subscription
Subscribe to Cluster Resources
Watch Kubernetes cluster resources in real-time.Kubernetes Contexts Subscription
Subscribe to K8s Context Changes
Monitor Kubernetes connection/context changes.MeshModel Summary Subscription
Subscribe to MeshModel Summary
Watch for changes in MeshModel statistics.JavaScript Implementation
Using graphql-ws
Using Apollo Client
React Hook Example
Python Implementation
Best Practices
Connection Management
- Reconnect on Disconnect: Implement automatic reconnection logic
- Heartbeat: Send periodic pings to keep connection alive
- Clean Shutdown: Properly unsubscribe before closing
Resource Management
- Limit Active Subscriptions: Don’t subscribe to too many streams simultaneously
- Pagination: Use appropriate page sizes for bulk subscriptions
- Filter Early: Apply filters to reduce data volume
Error Handling
- Handle Connection Errors: Network failures, authentication errors
- Handle Subscription Errors: Invalid queries, authorization failures
- Graceful Degradation: Fall back to polling if WebSocket fails
Troubleshooting
Connection Refused
Issue: Cannot establish WebSocket connection Solution:- Verify Meshery Server is running
- Check firewall rules allow WebSocket connections
- Ensure using correct protocol (
ws://orwss://)
Authentication Failed
Issue: WebSocket connection closes immediately Solution:- Verify token is valid and not expired
- Check token is included in
connectionParams - Ensure token has necessary permissions
No Data Received
Issue: Subscription established but no events received Solution:- Verify filters are not too restrictive
- Check connection IDs are valid
- Ensure relevant events are being generated