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§
- Discovery
Info - Discovery information about the engine.
- Emergent
Handler - A Handler primitive that subscribes to and publishes messages.
- Emergent
Message - Standard message envelope for all Emergent communications.
- Emergent
Sink - A Sink primitive that subscribes to messages from the Emergent engine.
- Emergent
Source - A Source primitive that publishes messages to the Emergent engine.
- Message
Stream - An async stream of messages received from subscriptions.
- Primitive
Info - Information about a registered primitive.
- Topology
Primitive - Information about a primitive in the topology.
- Topology
State - Current topology state (all primitives).
Enums§
- Client
Error - Client errors.
Traits§
- Into
Subscription - 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.