pub struct EmergentSource { /* private fields */ }Expand description
A Source primitive that publishes messages to the Emergent engine.
Sources are the ingress point for data entering the workflow. They can only publish messages (fire-and-forget) and cannot subscribe to receive messages.
§Example
use emergent_client::{EmergentSource, EmergentMessage};
use serde_json::json;
let source = EmergentSource::connect("my_source").await?;
loop {
let message = EmergentMessage::new("sensor.reading")
.with_payload(json!({"temperature": 72.5}));
source.publish(message).await?;
tokio::time::sleep(Duration::from_secs(1)).await;
}Implementations§
Source§impl EmergentSource
impl EmergentSource
Sourcepub async fn connect(name: &str) -> Result<Self>
pub async fn connect(name: &str) -> Result<Self>
Connect to the Emergent engine as a Source.
The name parameter identifies this source in logs and tracing.
§Errors
Returns an error if the connection fails or the engine is not running.
Sourcepub async fn connect_to(name: &str, socket_path: &Path) -> Result<Self>
pub async fn connect_to(name: &str, socket_path: &Path) -> Result<Self>
Connect to the Emergent engine at a specific socket path.
This is useful for testing or when connecting to a non-default socket.
§Errors
Returns an error if the connection fails or the engine is not running.
Sourcepub async fn publish(&self, message: EmergentMessage) -> Result<()>
pub async fn publish(&self, message: EmergentMessage) -> Result<()>
Publish a message to the engine (fire-and-forget).
The message will be routed to any Handlers or Sinks subscribed to its type.
§Errors
Returns an error if the message cannot be sent.
Sourcepub async fn publish_ack(&self, message: EmergentMessage) -> Result<()>
pub async fn publish_ack(&self, message: EmergentMessage) -> Result<()>
Publish a message with broker acknowledgment (backpressure).
Unlike [publish], this waits for the engine’s message broker to confirm
it has processed and forwarded the message before returning. This provides
natural backpressure — the caller cannot outpace the broker.
Used internally by [publish_all] and [publish_stream].
§Errors
Returns an error if the broker rejects the message or times out.
Sourcepub async fn publish_all(
&self,
messages: impl IntoIterator<Item = EmergentMessage>,
) -> Result<usize>
pub async fn publish_all( &self, messages: impl IntoIterator<Item = EmergentMessage>, ) -> Result<usize>
Publish all messages from an iterator.
Sends each message individually with broker acknowledgment so subscribers begin consuming immediately. Stops on the first error.
Returns the number of messages successfully published.
§Errors
Returns the first publish error encountered.
Sourcepub async fn publish_stream<S>(&self, stream: S) -> Result<usize>
pub async fn publish_stream<S>(&self, stream: S) -> Result<usize>
Publish messages from an async stream.
Consumes the stream, publishing each message individually with broker acknowledgment so subscribers begin consuming immediately. Stops on the first publish error or when the stream ends.
Returns the number of messages successfully published.
§Errors
Returns the first publish error encountered.
Sourcepub async fn discover(&self) -> Result<DiscoveryInfo>
pub async fn discover(&self) -> Result<DiscoveryInfo>
Discover available message types and primitives.
§Errors
Returns an error if the discovery request fails.