Kincir is a unified message streaming library that provides a consistent interface for
working with multiple message broker backends. It simplifies the process of building
message-driven applications by offering:
- A unified API for publishing and subscribing to messages
- Support for multiple message broker backends (Kafka, RabbitMQ)
- Message routing with customizable handlers
- Built-in logging capabilities
- Message tracking with UUID generation
- Extensible message metadata
Quick Start
use kincir::rabbitmq::{RabbitMQPublisher, RabbitMQSubscriber};
use kincir::router::{Router, Logger, StdLogger};
use kincir::Message;
use std::sync::Arc;
use std::pin::Pin;
use std::future::Future;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let logger = Arc::new(StdLogger::new(true, true));
let publisher = Arc::new(RabbitMQPublisher::new("amqp://localhost:5672").await?);
let subscriber = Arc::new(RabbitMQSubscriber::new("amqp://localhost:5672").await?);
let handler = Arc::new(|msg: Message| -> Pin<Box<dyn Future<Output = Result<Vec<Message>, Box<dyn std::error::Error + Send + Sync>>> + Send>> {
Box::pin(async move {
let mut processed_msg = msg;
processed_msg.metadata.insert("processed".to_string(), "true".to_string());
Ok(vec![processed_msg])
})
});
let router = Router::new(
logger,
"input-queue".to_string(),
"output-queue".to_string(),
subscriber,
publisher,
handler,
);
router.run().await
}