Expert guidance for developing the legend-saga Rust library for microservice communication via RabbitMQ with saga patterns and audit logging.
Expert guidance for developing the **legend-saga** Rust library (v0.0.41) - a production-ready library for microservice communication via RabbitMQ with saga patterns and audit logging.
The legend-saga library provides:
When working with this codebase, follow these procedures:
**Running code quality checks:**
```bash
make format # Format code with rustfmt
make lint-fix # Fix linting issues with clippy
make test # Run full test suite (starts Docker, runs tests)
make all # Run everything (prettier + format + lint-fix + test)
```
**CRITICAL TESTING REQUIREMENT:**
**For debugging individual tests:**
```bash
LOG_LEVEL=info cargo test --lib test_name -- --test-threads=1 --nocapture --color always
```
**Event Flow:**
```
Event Published → Event Received → Audit.Received emitted
↓
Event Processing
↓
┌──────────────┴──────────────┐
↓ ↓
Success: Audit.Processed Failure: Audit.DeadLetter
↓ ↓
ACK event NACK event
```
**Core Components:**
Follow this exact sequence:
```rust
// Step 1: Add variant to events.rs
pub enum MicroserviceEvent {
// ...
MyNewEvent,
}
// Step 2: Create payload struct
#[derive(Serialize, Deserialize)]
pub struct MyNewEventPayload {
pub field: String,
}
// Step 3: Update routing keys in queue_consumer_props.rs
// Add routing configuration for your event
// Step 4: Implement EventHandler
pub struct MyEventHandler;
impl EventHandler for MyEventHandler {
async fn handle(&self, delivery: Delivery) -> Result<(), RabbitMQError> {
// Process event logic here
Ok(())
}
}
// Step 5: Write tests with TestSetup
#[tokio::test]
async fn test_my_new_event() {
let setup = TestSetup::new().await;
// Test logic
}
```
Required steps:
1. Add variant to `AvailableMicroservices` enum
2. Define queue properties in `queue_consumer_props.rs`
3. Use `RabbitMQClient::microservice_consumer()` in `start.rs`
4. Write integration tests with `TestSetup`
**DO:**
**DON'T:**
When modifying functionality, refer to:
| File | Purpose | Common Tasks |
|------|---------|--------------|
| `events.rs` | Event type definitions | Add new events, payloads |
| `events_consume.rs` | Core event handling logic | Modify processing, ack/nack |
| `start.rs` | Connection management | Add microservice consumers |
| `consumers.rs` | RabbitMQ infrastructure | Exchange/queue setup |
| `publish_event.rs` | Event publishing methods | Add new publish patterns |
| `nack.rs` | Retry/dead-letter strategies | Adjust backoff algorithms |
| `queue_consumer_props.rs` | Queue/routing configuration | Define new queues |
| `test.rs` | Test utilities and setup | Enhance test infrastructure |
| `connection.rs` | Low-level RabbitMQ connections | Connection pooling, channels |
**Enable detailed logging:**
```bash
LOG_LEVEL=debug cargo test --lib test_name -- --test-threads=1 --nocapture
```
**Check RabbitMQ containers:**
```bash
docker compose ps
docker compose logs rabbitmq
```
**Common issues:**
Before submitting changes:
1. **Thread Safety**: Always use `--test-threads=1` for tests due to shared RabbitMQ state
2. **Audit Loop Prevention**: Never emit audit events from `AuditHandler`
3. **Testing**: Integration tests must use `TestSetup` infrastructure
4. **Naming**: Use `QueueConsumerProps` for all queue/exchange configuration
5. **Pattern Consistency**: Follow existing code patterns before inventing new approaches
**Running full test suite:**
```bash
make test
```
**Adding a new event with full implementation:**
```bash
```
**Debugging a failing test:**
```bash
LOG_LEVEL=debug cargo test --lib test_audit_received -- --test-threads=1 --nocapture --color always
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/rust-library-development/raw