2 unstable releases
new 0.1.0 | Apr 11, 2025 |
---|---|
0.0.1 | Mar 6, 2025 |
#1609 in Asynchronous
58 downloads per month
215KB
5K
SLoC
srad
srad
is a Sparkplug edge node and application development framework in Rust.
Additional information for this crate can be found in the docs.
Overview
srad
aims to make it easy as possible to build reliable, fast, and resource efficient Sparkplug B Edge Nodes and Applications with minimal overhead.
Getting Started
Examples
A simple Edge Node
use srad::{client_rumqtt, eon::{EoN, EoNBuilder, NoMetricManager}};
#[tokio::main]
async fn main() {
let opts = client_rumqtt::MqttOptions::new("foo:bar", "localhost", 1883);
let (eventloop, client) = client_rumqtt::EventLoop::new(opts, 0);
let (mut eon, handle) = EoNBuilder::new(eventloop, client)
.with_group_id("foo")
.with_node_id("bar")
.with_metric_manager(NoMetricManager::new())
.build().unwrap();
eon.run().await;
}
A simple Application
use srad::app::{App, SubscriptionConfig};
use srad::client_rumqtt;
#[tokio::main]
async fn main() {
let opts = client_rumqtt::MqttOptions::new("foo", "localhost", 1883);
let (eventloop, client) = client_rumqtt::EventLoop::new(opts, 0);
let (mut application, client) = App::new("foo", SubscriptionConfig::AllGroups, eventloop, client);
application
.on_online(||{ println!("App online") })
.on_offline(||{ println!("App offline") })
.on_nbirth(|id, _,timestamp, metrics| { println!("Node {id:?} born at {timestamp} metrics = {metrics:?}"); })
.on_ndeath(|id, _| { println!("Node {id:?} death"); })
.on_ndata(|id, _, timestamp, metrics| async move {
println!("Node {id:?} data timestamp = {timestamp} metrics = {metrics:?}");
})
.on_dbirth(|id, dev, _, timestamp, metrics| { println!("Device {dev} Node {id:?} born at {timestamp} metrics = {metrics:?}");})
.on_ddeath(|id, dev, _| { println!("Device {dev} Node {id:?} death"); })
.on_ddata(|id, dev, _, timestamp, metrics| async move {
println!("Device {dev} Node {id:?} timestamp {timestamp} metrics = {metrics:?}");
});
application.run().await;
}
More examples can be found in the examples and in the docs.
Dependencies
codegen
uses protoc
Protocol Buffers compiler to generate types.
Project Layout
srad
: Re-exports thesrad-*
crates under one package.srad-eon
: SDK for building Sparkplug Edge Nodes.srad-app
: SDK for building Sparkplug Applications.srad-client
: Trait and type definitions for implementing clients to interact with Sparkplug.srad-client-rumqtt
: Client implementation using rumqtt.srad-types
: Utility and Protobuf generated types.codegen
: Generates types from protobuf files inprotos
.examples
: Example Edge Node and application implementations.
License
This project is dual licensed under the MIT and APACHE licenses.
Dependencies
~6–15MB
~175K SLoC