Skip to main content

IIIClient

Struct IIIClient 

Source
pub struct IIIClient { /* private fields */ }
Expand description

WebSocket client for communication with the III Engine.

Create with register_worker.

Implementations§

Source§

impl IIIClient

Source

pub fn new(address: &str) -> Self

Create a new III with default worker metadata (auto-detected runtime, os, hostname)

Source

pub fn with_metadata(address: &str, metadata: WorkerMetadata) -> Self

Create a new III with custom worker metadata

Source

pub fn address(&self) -> &str

Get the engine WebSocket address this client connects to.

Source

pub fn set_metadata(&self, metadata: WorkerMetadata)

Set custom worker metadata (call before connect)

Source

pub fn set_headers(&self, headers: HashMap<String, String>)

Set custom HTTP headers for the WebSocket handshake (call before connect).

Source

pub fn set_otel_config(&self, config: OtelConfig)

Set OpenTelemetry configuration (call before connect)

Source

pub fn shutdown(&self)

Shutdown the III client and wait for the connection thread to finish.

This stops the connection loop, sends a shutdown signal, and joins the background connection thread. OpenTelemetry is flushed inside the connection thread before it exits.

Source

pub async fn shutdown_async(&self)

Shutdown the III client.

This stops the connection loop and sends a shutdown signal, but it does not join connection_thread.

Unlike shutdown, this method does not block to wait for run_connection() to finish, making it safe to call from an async context without stalling the executor. The OpenTelemetry flush (telemetry::shutdown_otel()) still runs inside the connection thread after run_connection() returns, so it may not complete unless shutdown is used to join the thread.

Source

pub fn register_function( &self, id: impl Into<String>, registration: RegisterFunction, ) -> FunctionRef

Register a function with the engine.

Argument order matches the Node and Python SDKs: (id, registration).

§Arguments
§Panics

Panics if id is empty or already registered.

§Examples
use iii_sdk::{register_worker, InitOptions, Error, RegisterFunction};
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;

#[derive(Deserialize, JsonSchema)]
struct Input { name: String }
#[derive(Serialize, JsonSchema)]
struct Output { message: String }

async fn greet(input: Input) -> Result<Output, Error> {
    Ok(Output { message: format!("Hello, {}!", input.name) })
}

let worker = register_worker("ws://localhost:49134", InitOptions::default());
worker.register_function(
    "greetings::greet",
    RegisterFunction::new_async(greet).description("Greets a user"),
);

Registration metadata stays on the builder, so the no-metadata path remains clean:

worker.register_function(
    "orders::create",
    RegisterFunction::new_async(|input: Value| async move { Ok(input) })
        .metadata(json!({"owner": "billing-team", "priority": "high"})),
);

Untyped handler taking serde_json::Value:

worker.register_function(
    "debug::echo",
    RegisterFunction::new_async(|input: Value| async move { Ok(json!({"echo": input})) }),
);

HTTP-invoked function:

let config = HttpInvocationConfig {
    url: "https://example.com/invoke".into(),
    method: HttpMethod::Post,
    timeout_ms: Some(30_000),
    headers: HashMap::new(),
    auth: None,
};
worker.register_function("ext::lambda", RegisterFunction::http(config));
Source

pub fn register_trigger_type<H, C, R>( &self, trigger_type: RegisterTriggerType<H, C, R>, ) -> TriggerTypeRef<C, R>
where H: TriggerHandler + 'static,

Register a custom trigger type with the engine.

Returns a TriggerTypeRef handle that can register triggers and functions with compile-time validated types.

§Examples
let my_trigger = worker.register_trigger_type(
    RegisterTriggerType::new("my-trigger", "My custom trigger", MyHandler)
        .trigger_request_format::<MyConfig>()
        .call_request_format::<MyRequest>(),
);

// Compile-time safe: config must be MyConfig, function input must be MyRequest
my_trigger.register_function("my::handler", |req: MyRequest| -> Result<serde_json::Value, iii_sdk::Error> {
    Ok(serde_json::json!({ "data": req.data }))
});
my_trigger.register_trigger("my::handler", MyConfig { url: "/hook".into() });
Source

pub fn unregister_trigger_type(&self, id: impl Into<String>)

Unregister a previously registered trigger type.

Source

pub fn register_trigger( &self, input: RegisterTriggerInput, ) -> Result<Trigger, Error>

Bind a trigger configuration to a registered function.

§Arguments
  • input - Trigger registration input with trigger_type, function_id, and config.
§Examples
let trigger = worker.register_trigger(RegisterTriggerInput {
    trigger_type: "http".to_string(),
    function_id: "greet".to_string(),
    config: json!({ "api_path": "/greet", "http_method": "GET" }),
    metadata: None,
})?;
// Later...
trigger.unregister();
Source

pub async fn trigger( &self, request: impl Into<TriggerRequestWithMetadata>, ) -> Result<Value, Error>

Invoke a remote function.

The routing behavior depends on the action field of the request:

§Examples
// Synchronous
let result = worker.trigger(TriggerRequest {
    function_id: "greet".to_string(),
    payload: json!({"name": "World"}),
    action: None,
    timeout_ms: None,
}).await?;

// Fire-and-forget
worker.trigger(TriggerRequest {
    function_id: "notify".to_string(),
    payload: json!({}),
    action: Some(TriggerAction::Void),
    timeout_ms: None,
}).await?;

// Enqueue
let receipt = worker.trigger(TriggerRequest {
    function_id: "iii::durable::publish".to_string(),
    payload: json!({"topic": "test"}),
    action: Some(TriggerAction::Enqueue { queue: "test".to_string() }),
    timeout_ms: None,
}).await?;

// Metadata
worker.trigger(
    TriggerRequest {
        function_id: "audit::write".to_string(),
        payload: json!({"event": "checkout"}),
        action: Some(TriggerAction::Void),
        timeout_ms: None,
    }
    .metadata(json!({"tenant": "acme"})),
).await?;
Source

pub fn get_connection_state(&self) -> IIIConnectionState

Get the current connection state.

Trait Implementations§

Source§

impl Clone for IIIClient

Source§

fn clone(&self) -> IIIClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more