MockForge AMQP
AMQP 0.9.1 protocol support for MockForge, enabling testing of message queue patterns, pub/sub, and enterprise messaging scenarios.
This crate provides a RabbitMQ-compatible AMQP broker implementation that allows you to mock message queue interactions, test pub/sub patterns, and simulate enterprise messaging scenarios in your applications.
Features
- AMQP 0.9.1 Protocol: Full RabbitMQ-compatible protocol support
- Mock Broker: Simulate message broker behavior for testing
- Exchange Management: Direct, topic, headers, and fanout exchanges
- Queue Management: Dynamic queue creation and management
- Message Routing: Flexible message routing and binding rules
- Consumer Simulation: Mock consumer behavior and acknowledgments
- Fixture Support: Pre-configured broker states and message flows
Quick Start
Basic AMQP Broker
use AmqpBroker;
use AmqpConfig;
async
Core Components
AmqpBroker
The main broker implementation that handles AMQP connections and protocol operations:
use AmqpBroker;
use AmqpConfig;
let config = default;
let spec_registry = new;
let broker = new;
// The broker handles:
// - Connection establishment and authentication
// - Channel management
// - Exchange and queue operations
// - Message publishing and consumption
Exchange Management
Support for different AMQP exchange types:
use ;
// Create exchange manager
let mut exchange_manager = new;
// Declare exchanges
exchange_manager.declare_exchange?;
// Bind queues to exchanges
exchange_manager.bind_queue?;
Queue Management
Dynamic queue creation and management:
use QueueManager;
// Create queue manager
let mut queue_manager = new;
// Declare a queue
queue_manager.declare_queue?;
// Publish messages to queue
queue_manager.publish_message?;
Message Handling
Publishing Messages
use AmqpMessage;
// Create a message
let message = AmqpMessage ;
// Publish through broker
broker.publish_message.await?;
Consumer Simulation
use ConsumerManager;
// Create consumer manager
let consumer_manager = new;
// Register a consumer
consumer_manager.register_consumer?;
Fixture System
Define broker configurations and message flows using fixtures:
# amqp-fixture.yaml
exchanges:
- name: "orders_exchange"
type: "topic"
durable: true
bindings:
- queue: "order_processing"
routing_key: "orders.#"
queues:
- name: "order_processing"
durable: true
messages:
- exchange: "orders_exchange"
routing_key: "orders.created"
body: '{"order_id": "12345", "amount": 99.99}'
properties:
content_type: "application/json"
Loading Fixtures
use AmqpSpecRegistry;
// Create spec registry
let registry = new;
// Load fixture from file
registry.load_fixture_from_file.await?;
// Or create fixture programmatically
use AmqpFixture;
let fixture = AmqpFixture ;
registry.add_fixture?;
Protocol Support
MockForge AMQP supports the full AMQP 0.9.1 protocol including:
- Connection Operations: Open, close, authentication
- Channel Management: Multiple channels per connection
- Exchange Operations: Declare, delete, bind, unbind
- Queue Operations: Declare, delete, bind, unbind, purge
- Message Operations: Publish, consume, acknowledge, reject
- Transaction Support: Basic transaction semantics
- QoS Settings: Prefetch and flow control
Testing AMQP Clients
Use MockForge AMQP to test AMQP client applications:
use ;
use task;
async
Configuration
AmqpConfig
use AmqpConfig;
let config = AmqpConfig ;
Performance
MockForge AMQP is optimized for testing scenarios:
- In-Memory Operations: Fast message routing without persistence
- Concurrent Connections: Handle multiple simultaneous AMQP clients
- Low Latency: Minimal overhead for message operations
- Scalable: Support for high-throughput testing scenarios
Integration with MockForge
MockForge AMQP integrates seamlessly with the MockForge ecosystem:
- MockForge Core: Shared configuration and logging
- MockForge CLI: Command-line interface for AMQP broker management
- MockForge Plugins: Extend AMQP functionality with custom plugins
Examples
See the examples directory for complete working examples including:
- Basic AMQP broker setup
- Message routing scenarios
- Consumer testing patterns
- Integration testing with real AMQP clients
Related Crates
mockforge-core: Core mocking functionalitylapin: Underlying AMQP client library
License
Licensed under MIT OR Apache-2.0