# RabbitMQ Test Suite This directory contains comprehensive tests for different RabbitMQ exchange types and patterns. ## Test Files ### Individual Test Files 1. **`run_fanout_test.py`** - Tests Fanout Exchange - Broadcasts messages to all bound queues - Demonstrates one-to-many messaging pattern - Run: `python run_fanout_test.py` 2. **`run_direct_test.py`** - Tests Direct Exchange - Routes messages based on exact routing key matches - Demonstrates selective message routing - Run: `python run_direct_test.py` 3. **`run_topic_test.py`** - Tests Topic Exchange - Routes messages using wildcard patterns (* and #) - Demonstrates hierarchical message routing - Run: `python run_topic_test.py` 4. **`run_multi_queue_test.py`** - Tests Multi-Queue Load Balancing - Distributes messages across multiple queues - Demonstrates load balancing and parallel processing - Run: `python run_multi_queue_test.py` ### Combined Test File 5. **`test.py`** - Runs all tests sequentially - Executes all exchange type tests in order - Run: `python test.py` ## Test Features ### Producer and Consumer Coordination - Each test starts consumers in the background - Producers send messages after consumers are ready - Tests demonstrate real-time message processing - Automatic cleanup and task cancellation ### Message Patterns Tested #### Fanout Exchange - **Pattern**: One-to-many broadcasting - **Queues**: 3 queues (demo.fanout.queue-0, demo.fanout.queue-1, demo.fanout.queue-2) - **Behavior**: All queues receive every message - **Use Case**: Notifications, announcements, logging #### Direct Exchange - **Pattern**: Exact routing key matching - **Queues**: error, warning, info (with debug routing to info) - **Behavior**: Messages routed based on exact routing key - **Use Case**: Log level routing, priority-based processing #### Topic Exchange - **Pattern**: Wildcard pattern matching - **Queues**: Critical, Success, Failed - **Behavior**: Messages routed using * and # wildcards - **Use Case**: Hierarchical event routing, microservice communication #### Multi-Queue Load Balancing - **Pattern**: Round-robin distribution - **Queues**: 3 balanced queues - **Behavior**: Messages distributed evenly across queues - **Use Case**: Horizontal scaling, parallel processing ## Running Tests ### Prerequisites - RabbitMQ server running on localhost:5673 - Python 3.7+ with asyncio support - Required packages: aio-pika ### Individual Test Execution ```bash # Test Fanout Exchange python run_fanout_test.py # Test Direct Exchange python run_direct_test.py # Test Topic Exchange python run_topic_test.py # Test Multi-Queue Load Balancing python run_multi_queue_test.py ``` ### Run All Tests ```bash python test.py ``` ## Test Output Each test provides detailed output showing: - Consumer startup messages - Message reception and processing - Queue routing behavior - Message persistence status - Test completion status ## Configuration Tests use the configuration from `config.py`: - RabbitMQ URI: `amqp://guest:guest@localhost:5673/` - Exchange and queue naming conventions - Message persistence settings ## Architecture ### Producer Side - Sets up exchanges and queues - Publishes test messages with appropriate routing keys - Handles connection management ### Consumer Side - Starts multiple consumers for different queues - Processes messages with simulated business logic - Demonstrates concurrent message handling ### Test Coordination - Uses asyncio tasks for concurrent execution - Implements proper startup/shutdown sequences - Ensures clean resource cleanup ## Extending Tests To add new test scenarios: 1. Create a new test file following the naming pattern `run_xxx_test.py` 2. Import appropriate producer and consumer functions 3. Implement the test logic with proper async/await patterns 4. Add consumer startup, message publishing, and cleanup phases 5. Update this README with the new test description