1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! 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
//!
//! ```rust,ignore
//! 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
//!
//! ```rust,ignore
//! 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
//!
//! ```rust,ignore
//! 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(())
//! }
//! ```
pub use ;
pub use ClientError;
pub use ;
pub use MessageStream;
pub use IntoSubscription;
/// Result type for client operations.
pub type Result<T> = Result;
/// Discovery information about the engine.
/// Information about a registered primitive.