StreamFly aims to be a stream-oriented Pub/Sub framework.
Cargo.toml
[dependencies]
streamfly = "0.1"
- create a streamfly client
let mut client = new_client(
"127.0.0.1:1318".parse()?,
"localhost",
Path::new("./certs/cert.pem"),
)
.await?;
- subscribe streams, and then receive data
let rx = client.subscribe(CHANNEL).await?;
loop {
let (_, mut reader) = rx.recv().await?;
tokio::spawn(async move { tokio::io::copy(&mut reader, &mut tokio::io::stdout()).await });
}
- publish a stream, and then write data to the stream
let (stream_id, mut writer) = client.open_stream(CHANNEL).await?;
writer.write_all(b"Hello, Streamfly!").await?;
- build streamfly cli command
RUSTFLAGS="--cfg s2n_quic_unstable" cargo build
- build examples
RUSTFLAGS="--cfg s2n_quic_unstable" cargo build --examples
- start the streamfly server
RUST_LOG=debug ./target/debug/streamfly serve
- start a receiver
RUST_LOG=debug ./target/debug/examples/sub
- start a sender
RUST_LOG=debug ./target/debug/examples/pub
- you can start another receiver
RUST_LOG=debug ./target/debug/examples/sub