lmrc-rabbitmq

Crates.iolmrc-rabbitmq
lib.rslmrc-rabbitmq
version0.3.16
created_at2025-11-30 23:19:07.070569+00
updated_at2025-12-11 13:29:08.883924+00
descriptionRabbitMQ management library for the LMRC Stack - comprehensive library for managing RabbitMQ installations on remote servers via SSH
homepagehttps://gitlab.com/lemarco/lmrc-stack/tree/main/libs/rabbitmq-manager
repositoryhttps://gitlab.com/lemarco/lmrc-stack
max_upload_size
id1958996
size56,802
Le Marc (lemarco)

documentation

https://docs.rs/lmrc-rabbitmq

README

lmrc-rabbitmq

RabbitMQ management library for the LMRC Stack - comprehensive library for managing RabbitMQ installations on remote servers via SSH.

Features

  • SSH-Based Installation: Automated RabbitMQ server installation on Ubuntu/Debian systems
  • User Management: Create, delete, and manage RabbitMQ users with tags
  • VHost Management: Create, delete, and list virtual hosts
  • Permission Management: Set, clear, and list permissions for users on vhosts
  • Plugin Management: Enable, disable, and list RabbitMQ plugins
  • Service Control: Start, stop, restart, and check status of RabbitMQ service

Installation

Add this to your Cargo.toml:

[dependencies]
lmrc-rabbitmq = "0.3.9"

Quick Start

use lmrc_rabbitmq::{RabbitMqManager, RabbitMqConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create configuration
    let config = RabbitMqConfig::builder()
        .version("latest")
        .admin_user("admin")
        .admin_password("secure_password")
        .enable_management(true)
        .management_port(15672)
        .amqp_port(5672)
        .configure_firewall(true)
        .build();

    // Create manager
    let manager = RabbitMqManager::new("192.168.1.10")
        .with_port(22)
        .with_user("root");

    // Install RabbitMQ
    manager.install(&config)?;

    // Get connection string
    let connection_string = manager.connection_string(
        "admin",
        "secure_password",
        "/",
        5672
    );
    println!("Connection string: {}", connection_string);

    Ok(())
}

Usage

Installing RabbitMQ

The manager handles the complete installation process:

let config = RabbitMqConfig::builder()
    .version("3.12.0")
    .admin_user("admin")
    .admin_password("my_password")
    .enable_management(true)
    .build();

let manager = RabbitMqManager::new("server.example.com")
    .with_user("root");

manager.install(&config)?;

This will:

  • Install Erlang dependencies
  • Add official RabbitMQ repositories
  • Install RabbitMQ server
  • Enable management plugin (if configured)
  • Create admin user
  • Remove default guest user
  • Configure firewall rules (UFW)

Managing Users

use lmrc_rabbitmq::{RabbitMqUser, RabbitMqManager};

let mut ssh_client = /* ... */;
let mut user_ops = lmrc_rabbitmq::operations::UserOperations::new(&mut ssh_client);

// Create user
let user = RabbitMqUser {
    username: "myuser".to_string(),
    password: "mypassword".to_string(),
    tags: vec!["administrator".to_string()],
};
user_ops.create_user(&user)?;

// List users
let users = user_ops.list_users()?;

Managing VHosts

use lmrc_rabbitmq::{RabbitMqVHost, operations::VHostOperations};

let mut vhost_ops = VHostOperations::new(&mut ssh_client);

// Create vhost
let vhost = RabbitMqVHost {
    name: "my-vhost".to_string(),
};
vhost_ops.create_vhost(&vhost)?;

Managing Permissions

use lmrc_rabbitmq::{RabbitMqPermission, operations::PermissionOperations};

let mut perm_ops = PermissionOperations::new(&mut ssh_client);

// Set permissions
let permission = RabbitMqPermission {
    user: "myuser".to_string(),
    vhost: "/".to_string(),
    configure: ".*".to_string(),
    write: ".*".to_string(),
    read: ".*".to_string(),
};
perm_ops.set_permissions(&permission)?;

Architecture

This library follows hexagonal architecture principles:

  • Ports: Defined in lmrc-ports crate
  • Adapters: SSH-based implementation using lmrc-ssh
  • Domain: RabbitMQ-specific operations and configuration

Error Handling

All operations return Result<T, RabbitMqError> with detailed error types:

use lmrc_rabbitmq::RabbitMqError;

match manager.install(&config) {
    Ok(_) => println!("Installation successful"),
    Err(RabbitMqError::Ssh(e)) => eprintln!("SSH error: {}", e),
    Err(RabbitMqError::InstallationFailed(msg)) => eprintln!("Installation failed: {}", msg),
    Err(e) => eprintln!("Error: {}", e),
}

License

Dual licensed under MIT OR Apache-2.0 (user's choice).

Contributing

This library is part of the LMRC Stack project.

Commit count: 0

cargo fmt