queue-runtime
A provider-agnostic queue abstraction for Rust, enabling reliable message processing across cloud platforms with session-based ordering, automatic retries, and dead letter queue handling.
Overview
queue-runtime provides a unified API for working with cloud message queues, currently supporting Azure Service Bus with AWS SQS support planned. Built with a hexagonal architecture, it allows applications to switch between providers without code changes while maintaining consistent behavior for session management, error handling, and message processing.
Designed for: GitHub bot applications and webhook processors that need reliable, ordered event processing with flexible deployment options.
Why queue-runtime?
- Write Once, Deploy Anywhere: Single codebase works with Azure Service Bus or AWS SQS
- Session-Based Ordering: Process related messages in order (e.g., all events for one pull request)
- Resilient by Default: Automatic retries with exponential backoff, circuit breakers, and dead letter queues
- Type-Safe: Compile-time guarantees for message handling with serde serialization
- Production-Ready: Built-in observability with tracing and metrics, comprehensive error handling
Architecture
queue-runtime uses hexagonal architecture (ports and adapters):
- Core Business Logic: Provider-agnostic queue operations, session management, retry logic
- Port Interfaces: Abstract traits defining queue and session operations
- Provider Adapters: Azure Service Bus implementation (AWS SQS coming soon)
- In-Memory Provider: For testing without external dependencies
This design ensures your business logic never depends directly on cloud provider SDKs, making testing easier and provider migration seamless.
Supported Platforms
- Rust: 1.90 or later
- Cloud Providers:
- ✅ Azure Service Bus (native session support)
- 🚧 AWS SQS (planned - emulated sessions)
- ✅ In-Memory (for testing)
- Operating Systems: Linux, Windows, macOS (x86_64 and ARM64)
- Async Runtime: Tokio 1.x
Features
- Provider Agnostic - Unified
QueueClientAPI works identically across Azure and AWS - Session Management - Ordered FIFO processing with native or emulated session support
- Retry Logic - Configurable exponential backoff with jitter and circuit breakers
- Dead Letter Queues - Automatic DLQ routing for poison messages and exceeded retries
- Type Safe - Strongly-typed message handling with
serdeserialization/deserialization - Observable - Integrated structured logging with
tracingand metrics collection - Secure - Credential management through Azure Identity SDK with managed identity support
- Testable - In-memory provider for unit tests with contract tests ensuring consistency
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Basic Message Sending and Receiving
use ;
use ;
use Bytes;
use Duration;
async
Session-Based Ordered Processing
use ;
use Bytes;
use Duration;
async
Azure Service Bus Example
use ;
use ;
use Bytes;
use Duration;
async
Error Handling and Dead Letter Queues
use ;
use Bytes;
use Duration;
async
async
Documentation
API Reference
Complete API documentation is available at docs.rs/queue-runtime.
Core Types
QueueClient- Main interface for queue operationsSessionClient- Interface for session-based ordered processingQueueClientFactory- Factory for creating queue clientsMessage- Message structure for sendingReceivedMessage- Message structure for receiving
Configuration Types
QueueConfig- Main configuration structureProviderConfig- Provider-specific configurationAzureServiceBusConfig- Azure Service Bus configurationAwsSqsConfig- AWS SQS configurationInMemoryConfig- In-memory provider configuration
Error Types
QueueError- Main error type for queue operationsValidationError- Validation error detailsConfigurationError- Configuration error details
Specifications
- Architecture Overview - System architecture and design principles
- API Specification - Complete specification documents
- Provider Specifications - Provider-specific implementation details
- Security Model - Security considerations and best practices
Module Documentation
- Client Module - Queue client implementation
- Messages - Message handling and serialization
- Sessions - Session-based ordering
- Retry Logic - Retry policies and exponential backoff
- Dead Letter Queues - DLQ handling
- Azure Provider - Azure Service Bus implementation
- AWS Provider - AWS SQS implementation (planned)
- Observability - Logging and metrics
Configuration
Azure Service Bus Configuration
Connection String Authentication
The simplest way to connect to Azure Service Bus is using a connection string:
use ;
use AzureAuthMethod;
use Duration;
let config = QueueConfig ;
Environment Variable Setup:
Then in your code:
let connection_string = var?;
let azure_config = AzureServiceBusConfig ;
Managed Identity Authentication (Recommended for Production)
For production deployments in Azure, use Managed Identity for passwordless authentication:
use ;
use Duration;
let azure_config = AzureServiceBusConfig ;
Environment Variable Setup:
# Only namespace required for managed identity
Service Principal Authentication
For development or CI/CD pipelines, use a service principal:
use ;
use Duration;
let azure_config = AzureServiceBusConfig ;
Environment Variable Setup:
AWS SQS Configuration (Planned)
AWS SQS support is planned for a future release. The configuration will support:
use ;
let config = QueueConfig ;
In-Memory Provider Configuration
For testing and development, use the in-memory provider:
use ;
use Duration;
let config = QueueConfig ;
Or use the test factory for quick setup:
let client = create_test_client;
Retry Configuration
Configure automatic retry behavior for transient failures:
let config = QueueConfig ;
The retry mechanism uses exponential backoff with jitter:
- First retry: ~2 seconds
- Second retry: ~4 seconds
- Third retry: ~8 seconds
- And so on...
Messages that exceed max_retry_attempts are automatically moved to the dead letter queue if enable_dead_letter is true.
Dead Letter Queue Configuration
Dead letter queues (DLQ) capture messages that cannot be processed successfully:
let config = QueueConfig ;
Manually sending to DLQ:
if let Some = client.receive_message.await?
Session Configuration
Configure session-based ordered processing:
// Azure Service Bus (native session support)
let azure_config = AzureServiceBusConfig ;
// In-memory provider (for testing)
let memory_config = InMemoryConfig ;
Environment-Based Configuration
Create environment-specific configurations:
use *;
Configuration Best Practices
-
Use Managed Identity in Production: Avoid storing connection strings in code or environment variables for production deployments on Azure.
-
Set Appropriate Timeouts: Match
default_timeoutto your expected message processing time. Too short causes unnecessary retries; too long delays error detection. -
Configure Retry Limits: Set
max_retry_attemptsbased on your failure rate tolerance. More retries = higher success rate but longer delays. -
Enable Dead Letter Queues: Always enable DLQ in production to prevent message loss and allow debugging failed messages.
-
Session Timeout Balance: Set
session_timeoutlong enough for message processing but short enough to recover from failures quickly (typically 5-10 minutes). -
Environment-Specific Settings: Use different retry and timeout values for development, staging, and production environments.
Examples
See the examples/ directory for complete working examples.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.