Expand description
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
- Message tracking with UUID generation
- Extensible message metadata
When the “logging” feature is enabled (default), Kincir also provides built-in logging capabilities.
When the “protobuf” feature is enabled, Kincir provides Protocol Buffers encoding/decoding capabilities.
§Example
Basic usage with RabbitMQ backend:
use kincir::Message;
use kincir::rabbitmq::{RabbitMQPublisher, RabbitMQSubscriber};
use kincir::router::Router;
use std::sync::Arc;
use std::pin::Pin;
use std::future::Future;
// Create and configure components
let publisher = Arc::new(RabbitMQPublisher::new("amqp://localhost:5672").await?);
let subscriber = Arc::new(RabbitMQSubscriber::new("amqp://localhost:5672").await?);
// Define message handler with explicit type signature
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 processed_msg = msg.with_metadata("processed", "true");
Ok(vec![processed_msg])
})
});
// Set up and run router (with or without logging based on feature)
// With logging (when "logging" feature is enabled)
use kincir::logging::{Logger, StdLogger};
let logger = Arc::new(StdLogger::new(true, true));
let router = Router::new(
logger,
"input-queue".to_string(),
"output-queue".to_string(),
subscriber.clone(),
publisher.clone(),
handler.clone(),
);
router.run().await
// Without logging (when "logging" feature is disabled)
let router = Router::new(
"input-queue".to_string(),
"output-queue".to_string(),
subscriber,
publisher,
handler,
);
router.run().await
Re-exports§
pub use logging::Logger;
pub use logging::NoOpLogger;
pub use logging::StdLogger;
pub use router::HandlerFunc;
pub use router::Router;
Modules§
- kafka
- Kafka implementation for the Kincir messaging system.
- logging
- Logging functionality for the Kincir messaging system.
- rabbitmq
- RabbitMQ implementation for the Kincir messaging system.
- router
- Message routing functionality for the Kincir messaging system.
Structs§
- Message
- Represents a message in the system with unique identification, payload, and metadata.
Traits§
- Publisher
- Defines the interface for publishing messages to a message broker.
- Subscriber
- Defines the interface for subscribing to messages from a message broker.