async-stomp

Crates.ioasync-stomp
lib.rsasync-stomp
version0.5.0
sourcesrc
created_at2024-10-29 08:50:47.112862
updated_at2024-10-29 10:40:13.101228
descriptionUnofficial successor to Asynchronous streaming STOMP client
homepagehttps://github.com/snaggen/async-stomp
repositoryhttps://github.com/snaggen/async-stomp
max_upload_size
id1426786
size83,331
Mattias Eriksson (snaggen)

documentation

README

async-stomp

An async STOMP client (and maybe eventually, server) for Rust, using the Tokio stack.

This is a fork of tokio-stomp-2, with the purpose of getting some basic maintenance going.

Examples

Sending a message to a queue.

use futures::prelude::*;
use async_stomp::client::Connector;
use async_stomp::ToServer;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
  let mut conn = Connector::builder()
    .server("127.0.0.1:61613")
    .virtualhost("/")
    .login("guest".to_string())
    .passcode("guest".to_string())
    .connect()
    .await
    .unwrap();

    conn.send(
      ToServer::Send {
        destination: "queue.test".into(),
        transaction: None,
        headers: None,
        body: Some(b"Hello there rustaceans!".to_vec()),
      }
      .into(),
    )
    .await
    .expect("sending message to server");
    Ok(())
}

Receiving a message from a queue.

use futures::prelude::*;
use async_stomp::client::Connector;
use async_stomp::client::Subscriber;
use async_stomp::FromServer;

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
  let mut conn = Connector::builder()
    .server("127.0.0.1:61613")
    .virtualhost("/")
    .login("guest".to_string())
    .passcode("guest".to_string())
    .connect()
    .await
    .unwrap();

  let subscribe = Subscriber::builder()
    .destination("queue.test")
    .id("custom-subscriber-id")
    .subscribe();

  conn.send(subscribe)
    .await
    .unwrap();

  while let Some(item) = conn.next().await {
    if let FromServer::Message { message_id, body, .. } = item.unwrap().content {
        println!("{:?}", body);
        println!("{}", message_id);
    }
  }
  Ok(())
}

For full examples, see the examples directory.

License: EUPL

Commit count: 65

cargo fmt