pub struct EdgeNode<T, S> { /* private fields */ }Expand description
The Edge Node engine.
Implementations§
Source§impl<T: MqttTransport, S: BdSeqStore> EdgeNode<T, S>
impl<T: MqttTransport, S: BdSeqStore> EdgeNode<T, S>
Sourcepub fn new(config: EdgeNodeConfig, transport: T, bdseq_store: S) -> Self
pub fn new(config: EdgeNodeConfig, transport: T, bdseq_store: S) -> Self
Create an engine. Call EdgeNode::connect to start the session.
Sourcepub async fn connect<D: DataSource>(&mut self, source: &D) -> Result<()>
pub async fn connect<D: DataSource>(&mut self, source: &D) -> Result<()>
Connect to the broker (registering the NDEATH will), subscribe to NCMD / per-device DCMD (and the primary host’s STATE if configured), then publish the birth sequence unless gated on a primary host.
§Errors
Propagates any transport error.
Sourcepub async fn publish_birth_sequence<D: DataSource>(
&mut self,
source: &D,
) -> Result<()>
pub async fn publish_birth_sequence<D: DataSource>( &mut self, source: &D, ) -> Result<()>
Sourcepub async fn publish_node_data(&mut self, metrics: Vec<Metric>) -> Result<()>
pub async fn publish_node_data(&mut self, metrics: Vec<Metric>) -> Result<()>
Publish an NDATA (report-by-exception) with the next sequence number.
§Errors
Returns SparkplugError::InvalidTopic if not online, or a transport error.
Sourcepub async fn publish_device_data(
&mut self,
device: &str,
metrics: Vec<Metric>,
) -> Result<()>
pub async fn publish_device_data( &mut self, device: &str, metrics: Vec<Metric>, ) -> Result<()>
Publish a DDATA for a born device.
§Errors
Returns an error if the device is not born or on transport failure.
Sourcepub async fn publish_device_death(&mut self, device: &str) -> Result<()>
pub async fn publish_device_death(&mut self, device: &str) -> Result<()>
Publish a DDEATH for a born device and mark it offline. DDEATH carries a
sequence number (tck-id-payloads-ddeath-seq) at QoS 0, retain=false.
§Errors
Returns an error if the device is not born, or on transport failure.
Sourcepub async fn handle_incoming<D: DataSource>(
&mut self,
message: &IncomingMessage,
source: &D,
) -> Result<EdgeEvent>
pub async fn handle_incoming<D: DataSource>( &mut self, message: &IncomingMessage, source: &D, ) -> Result<EdgeEvent>
Handle one inbound message, driving rebirth / primary-host transitions.
A Node Control/Rebirth = true NCMD re-publishes the birth sequence
(resetting seq to 0 and reusing the connection’s bdSeq), subject to
the rebirth debounce.
§Errors
Returns a decode/transport error; a malformed topic/payload is surfaced rather than panicking.
Sourcepub async fn recv_and_handle<D: DataSource>(
&mut self,
source: &D,
) -> Result<Option<EdgeEvent>>
pub async fn recv_and_handle<D: DataSource>( &mut self, source: &D, ) -> Result<Option<EdgeEvent>>
Receive the next inbound message and handle it; None if the stream closed.
§Errors
Propagates transport/decode errors.
Sourcepub async fn disconnect(&mut self) -> Result<()>
pub async fn disconnect(&mut self) -> Result<()>
Gracefully disconnect: publish the NDEATH explicitly (so the broker need not deliver the will), then disconnect.
§Errors
Propagates any transport error.