Expand description
PSRT server, cli and client library
https://github.com/alttch/psrt
Rust client example:
ⓘ
use psrt::client::{Client, Config};
use psrt::DEFAULT_PRIORITY;
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let test_topic = "test/topic1";
// define client configuration
let config = Config::new("localhost:2873")
.set_timeout(Duration::from_secs(5))
.build();
// connect PSRT client
let mut client = Client::connect(&config).await.expect("Failed to connect");
// subscribe to the topic
client.subscribe(test_topic.to_owned()).await.unwrap();
// get data channel
let data_channel = client.take_data_channel().unwrap();
let receiver_fut = tokio::spawn(async move {
// receive messages from the server
while let Ok(message) = data_channel.recv().await {
println!(
"topic: {}, data: {}",
message.topic(),
message.data_as_str().unwrap()
);
}
});
for _ in 0..3 {
// if required, check that the client is still connected
assert!(client.is_connected());
// publish a message
client
.publish(
DEFAULT_PRIORITY,
test_topic.to_owned(),
"hello".as_bytes().to_vec(),
)
.await
.unwrap();
sleep(Duration::from_secs(1)).await;
}
client.bye().await.unwrap();
receiver_fut.await.unwrap();
}
Python client (sync): https://github.com/alttch/psrt-py
Modules§
Structs§
Enums§
Constants§
- AUTH_
KEY_ AES128_ GCM - AUTH_
KEY_ AES256_ GCM - AUTH_
LOGIN_ PASS - COMM_
INSECURE - COMM_
TLS - CONTROL_
HEADER - DATA_
HEADER - DEFAULT_
PRIORITY - OP_BYE
- OP_NOP
- OP_
PUBLISH - OP_
PUBLISH_ NO_ ACK - OP_
PUBLISH_ REPL - OP_
SUBSCRIBE - OP_
UNSUBSCRIBE - PROTOCOL_
VERSION - RESPONSE_
ERR - RESPONSE_
ERR_ ACCESS - RESPONSE_
NOT_ REQUIRED - RESPONSE_
OK - RESPONSE_
OK_ WAITING - VERSION