Crates.io | rs_service_client |
lib.rs | rs_service_client |
version | 0.1.0 |
source | src |
created_at | 2024-11-18 21:33:02.624934 |
updated_at | 2024-11-18 21:33:02.624934 |
description | This library provides a client for interacting with Factory+ services in Rust applications. |
homepage | |
repository | |
max_upload_size | |
id | 1452681 |
size | 82,351 |
This library provides a client for interacting with Factory+ services in Rust applications.
cargo.toml
:cargo add rs_service_client
ServiceClient
:use rs_service_client::service::ServiceClient;
This example creates a ServiceClient
, subscribes to all messages on a Sparkplug device topic, and prints the received
data. Here we depend on the tokio async runtime. Note that we can iterate on the
receiver to pull the data when it's available, and the Sparkplug payloads are decoded for us.
use rs_service_client::service::mqtt::protocol::MqttProtocol;
use rs_service_client::service::ServiceClient;
#[tokio::main]
async fn main() {
let service_client = ServiceClient::from(
"my_username",
"my_password",
None,
None,
"https://my-directory-url.com",
)
.await;
let (mqtt_client, receiver) = service_client
.mqtt_interface
.get_mqtt_client(MqttProtocol::TLS, 8883, "my_client_id")
.await
.expect("Couldn't create MQTT client");
mqtt_client.subscribe("spBv1.0/my-group/+/my-node/my-device", 0);
let mut message_iterator = receiver.iter();
loop {
if let Some((topic, payload)) = message_iterator.next() {
println!("{}", payload);
}
}
}
There is no synchronous implementation of this service client.