Skip to content

Latest commit

 

History

History

client

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Selium Client

This is the client library for the Selium platform. Clients of the Selium server should implement this library to send data to and/or receive data from the server.

Running the Examples

Before running the examples, you should generate a set of self-signed certificates to use for authenticating the client and server via mTLS.

You can do so via the selium-tools binary included in the workspace:

$ cargo run --bin selium-tools gen-certs

Getting Started

Once you've started a Selium server (see the server's README.md for details), use the client library to start sending and receiving messages.

Here's a minimal example:

use futures::SinkExt;
use selium::{prelude::*, std::codecs::StringCodec};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let connection = selium::client()
        .with_certificate_authority("certs/client/ca.der")?
        .with_cert_and_key(
            "certs/client/localhost.der",
            "certs/client/localhost.key.der",
        )?
        .connect("127.0.0.1:7001")
        .await?;

    let mut publisher = connection
        .publisher("/some/topic")
        .with_encoder(StringCodec)
        .open()
        .await?;

    publisher.send("Hello, world!".into()).await?;
    publisher.finish().await?;

    Ok(())
}

Familiar Features

Selium Client uses Rust's Futures and Tokio libraries under the hood for doing asynchronous I/O. If you are already familiar with these libs, then you already know how to drive Selium!

Take our example above:

let mut publisher = connection
    .publisher("/some/topic")
    ...;

Here, publisher is actually just a futures::Sink. This makes it instantly compatible with your existing streams/sinks:

let my_stream = ...; // whatever floats your boat!

my_stream.forward(publisher);

Now you're publishing messages!

There's lots more Selium can do, like sending things other than strings. Be sure to checkout the user guide for more details.