nsq-async-rs
Read this in other languages: English, 简体中文
A high-performance, reliable NSQ client library written in Rust. This project provides similar functionality and interfaces to the official go-nsq implementation within the Rust ecosystem.
Features
- ✨ Asynchronous I/O support (based on tokio)
- 🚀 High-performance message processing
- 🔄 Automatic reconnection and error retry
- 🔍 Support for nsqlookupd service discovery
- 🛡️ Graceful shutdown support
- 📊 Built-in message statistics
- ⚡ Delayed publishing support
- 📦 Batch publishing support
- 💫 Feature parity with the official go-nsq client
Installation
Add the following dependency to your Cargo.toml file:
[]
 = "0.1.0"
Quick Start
Consumer Example
use ;
use Result;
use Message;
;
async 
Producer Example
use Producer;
use Result;
async 
Configuration Options
Consumer Configuration
ConsumerConfig 
Advanced Features
Delayed Publishing
producer.publish_with_delay.await?;
Batch Publishing
let messages = vec!;
producer.publish_multiple.await?;
Error Handling
This library uses thiserror to provide detailed error types, including:
- Connection errors
- Protocol errors
- Timeout errors
- Message handling errors
- Configuration errors
Connection Pool
nsq-async-rs includes a built-in connection pool implementation that efficiently manages and reuses NSQ connections:
// Create a custom connection pool configuration
let pool_config = ConnectionPoolConfig ;
// Create the connection pool
let pool = create_connection_pool;
// Use the connection pool with a producer
let producer = new_producer.with_connection_pool;
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
MIT License
Implementation Notes
This project was designed and implemented with reference to NSQ's official Go client library go-nsq, including:
- Message processing flow
- Connection management mechanisms
- Error handling strategies
- Configuration parameter design
- Graceful shutdown mechanism
While maintaining functional parity with go-nsq, we've fully leveraged Rust language features to provide:
- Stricter type safety
- Asynchronous support based on tokio
- Rust-style error handling
- Improved memory safety guarantees