Crate psrt

Source
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§

client
PSRT client module
comm
Internal socket communication wrapper

Structs§

Error
Message

Enums§

ErrorKind

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

Statics§

AUTHOR

Functions§

is_unix_socket
reduce_timeout