7 releases

0.0.8 Mar 25, 2022
0.0.7 Mar 25, 2022
0.0.6 Sep 11, 2021
0.0.5 Aug 19, 2021
0.0.2 Jul 31, 2021

#7 in #stomp

Download history 4/week @ 2024-01-21 10/week @ 2024-02-18 13/week @ 2024-02-25 15/week @ 2024-03-03 10/week @ 2024-03-10 18/week @ 2024-03-17 87/week @ 2024-03-31

117 downloads per month

MIT license

45KB
1K SLoC

stomp-rs

Client

Creating new connection:

let client = Client::connect(
    ClientBuilder::new("127.0.0.1:61613")
).await?;

Subscribing:

let (sender, mut receiver) = channel(16);

tokio::spawn(async move {
  match receiver.recv().await {
    Some(frame) => { /* process frame */}
    None => { }
  }
});
client.subscribe(
    Subscribe::new_with_random_id("/topic/test"),
    sender
).await

Sending:

client.send(
    Send::new("/topic/test")
      .body("test-message")
).await

Transaction:

let transaction = client.begin().await?;

transaction.send(
    Send::new("/topic/test")
      .body("test-message")
).await

lib.rs:

Stomp lib

Usage

Creating a client:

use stomp_rs::client::{Client, ClientBuilder};
use tokio::net::TcpStream;
use tokio::sync::mpsc::channel;
use std::error::Error;

async fn connect() -> Result<Client, Box<dyn Error>> {
  Client::connect(
      ClientBuilder::new("127.0.0.1:61613")
  ).await
}

Emitting a new frame:

use stomp_rs::protocol::frame::Send;
use stomp_rs::client::Client;
use std::error::Error;;

async fn send_example(client: &Client) -> Result<(), Box<dyn Error>> {
  client.send(
      Send::new("/topic/test")
        .body("test-message")
  ).await
}

Subscribe:

use stomp_rs::client::Client;
use stomp_rs::protocol::frame::Subscribe;
use tokio::sync::mpsc::{channel, Sender, Receiver};
use std::error::Error;
use stomp_rs::protocol::{Frame, ServerCommand};
use std::future::Future;
use std::sync::Arc;

async fn subscribe_example(client: Arc<Client>)-> Result<(), Box<dyn Error>> {
  let (sender, mut receiver): (Sender<Frame<ServerCommand>>, Receiver<Frame<ServerCommand>>) = channel(16);

  let subscriber_client = Arc::clone(&client);
  tokio::spawn(async move {
    match receiver.recv().await {
      Some(frame) => {
        /* process frame */

        // Send ack to server
        subscriber_client.ack(frame.ack().unwrap())
            .await;
      }
      None => { }
    }
  });

  client.subscribe(
      Subscribe::new_with_random_id("/topic/test"),
      sender
  ).await
}

Dependencies

~3–11MB
~83K SLoC