Skip to main content
EngineBuilder provides a fluent API for configuring, building, and running the iii framework engine. It handles module registration, initialization, and server lifecycle.

Constructor

EngineBuilder::new()

Creates a new EngineBuilder with default settings.
Returns: A new EngineBuilder instance with:
  • Default module registry (from inventory)
  • Address set to 0.0.0.0:49134
  • Empty module list
Example:

Configuration Methods

address()

Sets the server address and port.
&str
required
Server address in format host:port (e.g., "0.0.0.0:3000")
Example:

config_file_or_default()

Loads configuration from a YAML file if it exists, otherwise uses default modules.
&str
required
Path to YAML configuration file (e.g., "config.yaml")
Returns: Result<Self> - Updated builder or error if config parsing fails Behavior:
  • If file exists: Parses YAML and loads modules from config
  • If file missing: Uses default modules registered via inventory
  • Supports environment variable expansion (see Configuration)
Example:
src/main.rs

register_module()

Registers a custom module type that can be instantiated by class name.
&str
required
Fully qualified class name for the module (e.g., "my::CustomModule")
Module
required
Type implementing the Module trait
Example:

add_module()

Adds a module instance to be loaded at runtime.
&str
required
Module class name (must be registered in the registry)
Option<Value>
default:"None"
Optional JSON configuration passed to the module’s create() method
Example:

Build and Execution

build()

Builds and initializes all configured modules.
Returns: Result<Self> - Builder with initialized modules or error Process:
  1. Ensures default metrics are available
  2. Adds mandatory modules if not present
  3. Creates all module instances via registry
  4. Calls initialize() on each module
  5. Registers module functions with the engine
Example:
src/main.rs
You must call build() before serve(). The builder will panic if you call serve() without building first.

serve()

Starts the WebSocket server and begins serving requests.
Returns: Result<()> - Blocks until shutdown signal received Behavior:
  1. Starts background tasks for all modules
  2. Starts channel TTL sweep task
  3. Sets up WebSocket routes:
    • / - Main worker connections
    • /ws/channels/{channel_id} - Channel-specific connections
  4. Binds TCP listener and starts serving
  5. Waits for shutdown signal (SIGTERM, SIGINT, or Ctrl+C)
  6. Calls destroy() on all modules for cleanup
Example:
src/main.rs

destroy()

Cleans up and destroys all modules. Called automatically by serve().
Returns: Result<()> - Success or first error encountered

Complete Examples

Basic Usage

src/main.rs

Custom Module Registration

Programmatic Configuration

Type Information

Module Trait Bound

Modules registered with register_module() must implement:

Configuration

Learn about EngineConfig and YAML structure

Module Trait

Module trait reference

Custom Modules

Build your own modules

Deployment

Production configuration guide