5. Bonus: Direct Exchange with Wabbit
The repo also includes a direct exchange example using the wabbit library, which provides a higher-level abstraction over AMQP.
It simplifies channel and message handling, but the underlying logic (Direct Exchange routing) remains the same.
How to Run the Examples
- Start RabbitMQ locally (via Docker or system install).
docker run -p 5672:5672 -p 15672:15672 rabbitmq:3-management
RabbitMQ Management UI: http://localhost:15672 (default login:guest/guest
). - Navigate to the example folder, e.g.:
cd direct/publisher go run main.go
- Run one or more consumers in separate terminals:
cd direct/consumer_1 go run main.go
- Observe how different exchanges deliver messages differently!
Quick Comparison
Exchange Type | Routing Logic | Example Use Case |
---|---|---|
Default | Queue name = routing key | Simple task queue |
Direct | Exact key match | Error vs info log separation |
Fanout | Broadcast to all queues | Notifications, cache invalidation |
Topic | Pattern match (*, #) | Orders by region, IoT sensors |
Headers | Match headers | Advanced filtering (not in repo) |
Conclusion
RabbitMQ exchanges give you powerful ways to route messages between producers and consumers.
- Use Default/Direct for simple exact matching.
- Use Fanout to broadcast to many consumers.
- Use Topic for flexible routing with patterns.
- (Optional) Use Headers for metadata-based filtering.
The examples in this repo are a great way to learn how these exchanges work in practice using Go.
Category: RabbitMQ