📡 Server-Sent Events (SSE) Example
Demonstrates Server-Sent Events for one-way real-time updates from server to client. Perfect for live dashboards, notifications, and monitoring systems where bi-directional communication isn't needed.
⏱️ Live Event Stream
Watch real-time server events appear below. Each message shows the current server time:
🔄 Connecting to event stream...
🔧 Technical Implementation
- EventSource API: Uses browser's native EventSource for automatic reconnection.
- Streaming Response: Long-lived HTTP connection with
text/event-streamcontent type. - Real-time Updates: Server pushes timestamped messages every second.
- Connection Monitoring: Displays database connection pool statistics.
📋 Key Files
app/controllers/sse_controller.rb- SseController#events - Server-Sent Events endpointapp/views/sse/index.html.erb- sse/index.html.erb - EventSource client code
🚀 Performance Benefits
SSE provides a lightweight alternative to WebSockets when you only need server-to-client communication. It is easier to use as it has automatic reconnection and built-in browser support. Falcon handles these persistent connections efficiently without blocking other requests.