Skip to main content

EmergentSource

Struct EmergentSource 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn publish_stream<S>(&self, stream: S) -> Result<usize>
where S: Stream<Item = EmergentMessage> + Unpin,

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.

Source

pub async fn discover(&self) -> Result<DiscoveryInfo>

Discover available message types and primitives.

§Errors

Returns an error if the discovery request fails.

Source

pub fn name(&self) -> &str

Get the name of this source.

Source

pub async fn disconnect(&self) -> Result<()>

Gracefully disconnect from the engine.

§Errors

Returns an error if the disconnection fails.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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<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