Crate kincir

Crate kincir 

Source
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};
use tokio::sync::Mutex;
let logger = Arc::new(StdLogger::new(true, true));
let router = Router::new(
    logger,
    "input-queue".to_string(),
    "output-queue".to_string(),
    Arc::new(Mutex::new(RabbitMQSubscriber::new("amqp://localhost:5672").await?)),
    publisher.clone(),
    handler.clone(),
);

router.run().await
// Without logging (when "logging" feature is disabled)
use tokio::sync::Mutex;
let subscriber_instance = RabbitMQSubscriber::new("amqp://localhost:5672").await?;
let router = Router::new(
    "input-queue".to_string(),
    "output-queue".to_string(),
    Arc::new(Mutex::new(subscriber_instance)),
    publisher,
    handler,
);

router.run().await

Re-exports§

pub use ack::AckConfig;
pub use ack::AckHandle;
pub use ack::AckMode;
pub use ack::AckStats;
pub use ack::AckSubscriber;
pub use ack::CompatSubscriber;
pub use logging::Logger;
pub use logging::NoOpLogger;
pub use logging::StdLogger;
pub use mqtt::MQTTPublisher;
pub use mqtt::MQTTSubscriber;
pub use mqtt::MQTTAckHandle;
pub use mqtt::MQTTAckSubscriber;
pub use rabbitmq::RabbitMQPublisher;
pub use rabbitmq::RabbitMQSubscriber;
pub use rabbitmq::RabbitMQAckHandle;
pub use rabbitmq::RabbitMQAckSubscriber;
pub use kafka::KafkaPublisher;
pub use kafka::KafkaSubscriber;
pub use kafka::KafkaAckHandle;
pub use kafka::KafkaAckSubscriber;
pub use router::HandlerFunc;
pub use router::Router;
pub use router::AckRouter;
pub use router::AckStrategy;
pub use router::RouterAckConfig;
pub use router::RouterAckStats;

Modules§

ack
Unified acknowledgment handling for message brokers
kafka
Kafka implementation for the Kincir messaging system.
logging
Logging functionality for the Kincir messaging system.
memory
In-memory message broker implementation
mqtt
rabbitmq
RabbitMQ implementation for the Kincir messaging system.
router
Message routing functionality for the Kincir messaging system.
tunnel

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.