A real-time chat application built with RabbitMQ message broker, using FastAPI and React client.
Watch the application in action:
Project implements a chat system with RabbitMQ for message exchange. Users can join different chat rooms, send messages, and receive real-time updates via WebSocket connections.
- Framework: FastAPI with async/await support
- Message Broker: RabbitMQ integration using
aio_pika - Real-time Communication: WebSocket endpoints for live chat
- User Authentication: UUID-based user identification system
- Room Management: Dynamic channel creation and switching
- Message Broadcasting: Topic-based exchange for room-specific messaging
- Connection Management: Tracks active WebSocket connections and user room assignments
GET /auth- Generate unique user IDPOST /send_message- Send chat message via HTTPWS /chat/{user_id}- WebSocket connection for real-time messagingGET /rooms- List active rooms and connections
- Exchange: Topic exchange (
chat_exchange) for routing messages - Routing Keys: Pattern
chat.{room_name}for room-based message delivery - Message Persistence: Non-durable queues (no message history)
- Framework: React 19 with Vite build tool
- HTTP Client: Axios for REST API communication
- WebSocket: Native WebSocket API for messaging
- User Authentication: Automatic user ID generation and management
- Room Switching: Change rooms on UI
- Message Display: Real-time message feed with sender identification
- Authentication System: Handles user ID generation and storage
- Message Input: Send messages to current room
- Room Management: Switch between chat rooms dynamically
- Message Feed: Display incoming messages with timestamps
- Error Handling: Connection and message validation
- RabbitMQ URL:
amqp://guest:guest@localhost:5672/ - Server Port: 8000 (configurable)
- Exchange Type: Topic exchange for flexible routing
- API URL:
http://localhost:8000 - WebSocket URL:
ws://localhost:8000
- Docker (for RabbitMQ)
- Python 3.8+ (for server)
- React.js 16+ (for client)
# Start RabbitMQ Docker container
bash rabbit.shcd server
pip install -r requirements.txt
# Additional dependencies: fastapi, uvicorn, aio-pika
python -m uvicorn core.server:app --host 0.0.0.0 --port 8000cd client
npm install
npm run dev- Start Services: Launch RabbitMQ, server, and client
- Authenticate: Click "Authenticate" to receive user ID
- Join Room: Enter room name and click "Change room"
- Send Messages: Type message and click "Send"
- Real-time Updates: Messages appear instantly via WebSocket
- Client sends message via WebSocket or HTTP
- Server publishes to RabbitMQ topic exchange
- Exchange routes to room-specific queues
- Consumers receive messages and forward to WebSocket clients
- Real-time display in client interface
- Rooms created automatically when first accessed
- No persistent room storage (created on-demand)
- Users can switch rooms without losing connection
- Each room isolated via routing keys
- Robust WebSocket connection with auto-cleanup
- User session management via UUID tracking
- Graceful disconnection and resource cleanup
- Error handling for connection failures
fastapi- Web frameworkaio-pika- Async RabbitMQ clientuvicorn- server
react- UI frameworkaxios- HTTP clientvite- Build tool and dev server
