#event-bus #pub-sub #kokoro #aop #pubsub

kokoro-default-impl

Kokoro's internal package, which implements some commonly used things

4 releases

0.0.6 Feb 28, 2024
0.0.5 Feb 19, 2024

#655 in Network programming

36 downloads per month
Used in 2 crates

Apache-2.0/MIT

35KB
772 lines

docs.rs Crates.io Version Crates.io License

Kokoro is a Rust-based meta-framework that prioritizes memory safety, performance, and stability to empower the creation of highly decoupled applications.


Advantages

  • Memory Safety ๐Ÿฆ€: Built with Rust's guarantees of memory safety, Kokoro eliminates the need for manual side-effect management.
  • High Performance โšก๏ธ: Designed for efficiency, Kokoro ensures rapid response times and exceptional performance.
  • Stable & Reliable ๐Ÿ—๏ธ: Continuously optimized, Kokoro aims to provide stable support for production environments in the future.
  • Dynamic Plugins ๐Ÿ”Œ: Supports dynamic plugins, including WASM and dynamic linking libraries, for functional expansion.
  • Hot Module Replacement ๐Ÿ”„: Simplifies the hot update process based on dynamic plugins, making it easy to understand and implement.
  • Flexibility ๐ŸŒŸ: Highly decoupled by nature, Kokoro allows for easy extension or modification. Modular, loosely coupled, hot-updatable, and distributed - all possible with Kokoro.

Getting Started

ๅฎ˜็ฝ‘ todo

Demo

use kokoro::{dynamic_plugin::toml::toml, prelude::*};
use kokoro_plugin_tiny_http_event::{http::Response, *};

fn main() -> Result<()> {
    // Create a context for the channel.
    let ctx = channel_ctx();
    // Initialize a new PluginFinder to search for plugins in the "./plugin" directory.
    let pf = PluginFinder::new("./plugin");
    // Find the "kokoro_plugin_tiny_http" plugin.
    let plugin = pf.find("kokoro_plugin_tiny_http");
    // Define the configuration for the plugin using TOML format.
    let config = toml! {
        host = "0.0.0.0" // The host address where the server will listen.
        port = 1145      // The port number for the server.
    };
    // Load the plugin dynamically with the specified configuration.
    ctx.plugin_dynamic(plugin, Some(config.into()))?;
    // Subscribe to the 'hello' event.
    ctx.subscribe(hello);
    // Run the context synchronously.
    ctx.run_sync();

    // Return Ok if everything executes successfully.
    Ok(())
}

// Define a new Path named 'Hello' targeting the "/hello" endpoint.
path!(Hello, "/hello");
// Define the 'hello' function to handle requests to the 'Hello' path.
fn hello(req: PathQuery<Hello>) {
    // Check if there is a request and take ownership of it.
    if let Some(req) = req.take() {
        // Respond to the request with a "Hello World!" message.
        req.respond(Response::from_string("Hello World!")).unwrap();
    }
}

This code sets up a simple HTTP server that responds with โ€œHello World!โ€ when the โ€œ/helloโ€ path is accessed. It uses the tiny_http plugin for handling HTTP events.

Star History

Star History Chart

todo list

  • kokoro-default-impl
    • kokoro-plugin-impl
    • kokoro-thread-impl
    • kokoro-service-impl
  • kokoro-dynamic-plugin-impl
  • plugin config api
  • loader for dynamically and schematically loading plugins.
  • logger for uniform output logging of plugins.
  • k-onfig is used to hint configuration schema.
  • Satori (EventType only) for instant messaging or chatbots

lib.rs:

Some useful implementations

Like Context::default, Context::spwan

Dependencies

~2.5โ€“8.5MB
~56K SLoC