lib_broker is a high-performance, cross-language message broker library primarily designed for use with pgShield, but engineered to serve as a versatile, portable SDK for various programming environments. Leveraging Rust's cross-platform capabilities and performance, it offers a modular infrastructure mediator pattern with optional RabbitMQ and Apache Kafka integration.
- 🛡️ pgShield Integration: Optimized for seamless integration with pgShield, enhancing its functionality and performance.
- 🧩 Portable SDK: Designed to be easily adaptable for use in diverse projects and programming environments beyond pgShield.
- 🌐 Cross-Platform: Utilizes Rust's capabilities to ensure consistent performance across different operating systems.
- 🗣️ Language Agnostic: Provides easy integration with C, C++, Java, C#, and other languages, making it a versatile choice for multilingual projects.
- 🏗️ Modular Design: Implements a flexible mediator pattern, allowing for easy extension and customization of messaging infrastructure.
- 🦀 Rust Core: Leverages Rust's performance and safety guarantees.
- 🔌 Cross-Language Support: Easy integration with C, C++, Java, C#, and more.
- ⚙️ Flexible Configuration: Simple .cfg file for setup and customization.
- 🔧 Optional Integrations:
- 🐰 RabbitMQ support
- 🐘 Apache Kafka support
- 📁 File logging
- 🪟 Windows OutputDebugString
- 🐧 Linux syslog
- ⚡ Asynchronous Architecture: Built on Tokio for efficient async operations.
- 🔒 Thread-Safe: Designed for concurrent use in multi-threaded environments.
lib_broker was originally developed as a core component for pgShield, a PostgreSQL security enhancement tool. It serves as the primary message broker and communication facilitator within pgShield's architecture. However, recognizing its potential for broader applications, lib_broker has been designed with portability and flexibility in mind, allowing it to be used as a standalone SDK in various other projects.
Add this to your Cargo.toml:
[dependencies]
lib_broker = "0.1.0"- Download the pre-compiled binary for your platform from the releases page.
- Include the library in your project:
- For C/C++: Link against the provided .dll/.so file.
- For Java: Use the provided JAR file with JNA.
- For C#: Use P/Invoke to call the library functions.
use lib_broker::{get_broker, Message, Handler, BrokerError};
#[message_handler(TextMessage)]
fn handle_text_message(message: &TextMessage) -> Result<(), BrokerError> {
println!("Received: {:?}", message);
Ok(())
}
#[tokio::main]
async fn main() -> Result<(), BrokerError> {
let broker = get_broker().await?;
broker.send(TextMessage("Hello, World!".to_string())).await?;
Ok(())
}public class LibBrokerExample {
public static void main(String[] args) {
try (LibBroker broker = new LibBroker("lib_broker.cfg")) {
broker.registerHandler("TextMessage", (messageType, message) -> {
System.out.println("Received message: " + message);
return 0; // Success
});
broker.send("TextMessage", "Hello from Java!");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}using System;
class LibBrokerExample
{
static void Main()
{
using (var broker = new LibBroker("lib_broker.cfg"))
{
broker.RegisterHandler("TextMessage", (messageType, message) =>
{
Console.WriteLine($"Received message: {message}");
return 0; // Success
});
broker.Send("TextMessage", "Hello from C#!");
}
}
}Create a lib_broker.cfg file in your project directory:
# Logging configuration
log_directory = /var/log/lib_broker
log_rotation = daily
use_windows_debug = false
use_linux_syslog = false
# RabbitMQ configuration (if feature is enabled)
rabbitmq_url = amqp://guest:guest@localhost:5672
rabbitmq_exchange = lib_broker_exchange
# Kafka configuration (if feature is enabled)
kafka_brokers = localhost:9092,localhost:9093
kafka_topic = lib_broker_topic
- Ensure you have Rust and Cargo installed.
- Clone the repository:
git clone https://github.com/pgshield/lib_broker.git - Build the project:
cd lib_broker cargo build --release
Execute the test suite with:
cargo test
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.
- The Rust community for their excellent documentation and crates
- Contributors who have invested time and effort to help this project
Indrit - indrit.zeqiri@gmail.com
Project Link: https://github.com/pgshield/lib_broker
Built with ❤️ by the pgShield team