TLQ Rust Client
A high-performance, async Rust client for TLQ (Tiny Little Queue) - a minimal, in-memory message queue server.
Features
- Async/await support with Tokio
- Automatic retry with exponential backoff
- Builder pattern for flexible configuration
- Type-safe message handling
- Zero external dependencies (only tokio, serde, uuid, thiserror)
- High performance with minimal overhead
- Comprehensive documentation with examples and API reference
Installation
Add this to your Cargo.toml:
[]
= "0.2"
Quick Start
use TlqClient;
async
Configuration
Using the Builder Pattern
use TlqClient;
use Duration;
let client = builder
.host
.port
.timeout_ms
.max_retries
.retry_delay_ms
.build;
let client = with_config;
Configuration Options
host: Server hostname (default: "localhost")port: Server port (default: 1337)timeout: Request timeout (default: 30 seconds)max_retries: Maximum retry attempts (default: 3)retry_delay: Base delay between retries (default: 100ms)
Documentation
This crate provides comprehensive API documentation with examples for all public APIs. View the full documentation at docs.rs/tlq-client.
Key documentation highlights:
- Complete API reference with examples
- Error handling patterns and best practices
- Configuration options and builder patterns
- Usage examples for all operations
- Internal implementation details where relevant
API Reference
Core Methods
health_check()
Check if the TLQ server is responsive.
let is_healthy = client.health_check.await?;
add_message(body)
Add a message to the queue.
let message = client.add_message.await?;
get_messages(count)
Retrieve multiple messages from the queue.
let messages = client.get_messages.await?;
get_message()
Retrieve a single message from the queue.
if let Some = client.get_message.await?
delete_message(id) / delete_messages(ids)
Delete processed messages from the queue.
// Delete single message
client.delete_message.await?;
// Delete multiple messages
client.delete_messages.await?;
retry_message(id) / retry_messages(ids)
Return messages to the queue for retry.
// Retry single message
client.retry_message.await?;
// Retry multiple messages
client.retry_messages.await?;
purge_queue()
Remove all messages from the queue.
let purged_count = client.purge_queue.await?;
Error Handling
The client provides comprehensive error types:
use TlqError;
match client.add_message.await
Retryable Errors
Some errors are automatically retried:
if error.is_retryable
Examples
Worker Pattern
use TlqClient;
use ;
async
Batch Processing
let messages = client.get_messages.await?;
let mut successful = Vecnew;
let mut failed = Vecnew;
for msg in messages
// Delete successful messages
if !successful.is_empty
// Retry failed messages
if !failed.is_empty
Running Examples
The repository includes several example programs:
# Basic usage
# Worker pattern
# Batch processing
Testing
Run the test suite:
Run tests with coverage:
Performance
The client is designed for high performance:
- Minimal allocations
- Efficient serialization with serde
- Connection pooling (coming soon)
- Zero-copy where possible
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE-MIT file for details.
Related Projects
- TLQ Server - The TLQ server implementation
- TLQ Node.js Client
- TLQ Go Client
- TLQ Python Client