Skip to main content

Crate emergent_client

Crate emergent_client 

Source
Expand description

Emergent Client Library

This crate provides the client-side SDK for building Sources, Handlers, and Sinks that connect to the Emergent workflow engine.

§Primitives

Emergent uses three primitives that define how clients interact with the message bus:

  • EmergentSource - Publishes messages to the workflow (ingress from external world)
  • EmergentHandler - Subscribes to and publishes messages (transformation/processing)
  • EmergentSink - Subscribes to messages (egress to external world)

§Example: Source

use emergent_client::{EmergentSource, EmergentMessage};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let source = EmergentSource::connect("my_source").await?;

    let message = EmergentMessage::new("timer.tick")
        .with_payload(json!({"sequence": 1}));

    source.publish(message).await?;
    Ok(())
}

§Example: Handler

use emergent_client::{EmergentHandler, EmergentMessage};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let handler = EmergentHandler::connect("my_handler").await?;
    let mut stream = handler.subscribe(&["timer.tick"]).await?;

    while let Some(msg) = stream.next().await {
        // Process and publish transformed message
        let output = EmergentMessage::new("timer.processed")
            .with_causation_id(msg.id())
            .with_payload(json!({"original": msg.payload}));
        handler.publish(output).await?;
    }
    Ok(())
}

§Example: Sink

use emergent_client::EmergentSink;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let sink = EmergentSink::connect("my_sink").await?;
    let mut stream = sink.subscribe(&["timer.processed"]).await?;

    while let Some(msg) = stream.next().await {
        println!("Received: {} - {:?}", msg.message_type, msg.payload);
    }
    Ok(())
}

Modules§

helpers
Convenience functions for building Emergent primitives.
prelude
Convenient re-exports for common usage.
types
Core types for Emergent messages and primitives.

Structs§

DiscoveryInfo
Discovery information about the engine.
EmergentHandler
A Handler primitive that subscribes to and publishes messages.
EmergentMessage
Standard message envelope for all Emergent communications.
EmergentSink
A Sink primitive that subscribes to messages from the Emergent engine.
EmergentSource
A Source primitive that publishes messages to the Emergent engine.
MessageStream
An async stream of messages received from subscriptions.
PrimitiveInfo
Information about a registered primitive.
TopologyPrimitive
Information about a primitive in the topology.
TopologyState
Current topology state (all primitives).

Enums§

ClientError
Client errors.

Traits§

IntoSubscription
Trait for types that can be converted into subscription topics.

Functions§

create_message
Create a new message with the given type.

Type Aliases§

Result
Result type for client operations.