Indeed, there is no official SDK - but there are some other implementations you can have a look at it, like this one with the following example:
use tokio::time;
use azure_iot_sdk::{IoTHubClient, DeviceKeyTokenSource, Message};
#[tokio::main]
async fn main() -> azure_iot_sdk::Result<()> {
let iothub_hostname = "iothubname.azure-devices.net";
let device_id = "MyDeviceId";
let token_source = DeviceKeyTokenSource::new(
iothub_hostname,
device_id,
"TheAccessKey",
).unwrap();
let mut client =
IoTHubClient::new(iothub_hostname, device_id.into(), token_source).await?;
let mut interval = time::interval(time::Duration::from_secs(1));
let mut count: u32 = 0;
loop {
interval.tick().await;
let msg = Message::builder()
.set_body(format!("Message #{}", count).as_bytes().to_vec())
.set_message_id(format!("{}-t", count))
.build();
client.send_message(msg).await?;
count += 1;
}
Ok(())
}
Alternatively, If Rust is not a hard requirement, at least end-to-end, maybe you can have an independent service that deals with the operations with IoT Hub, and have it called from your Rust code as a normal REST service.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…