stomp_rs/
lib.rs

1//! # Stomp lib
2//!
3//! ## Usage
4//! Creating a client:
5//! ```no_run
6//! use stomp_rs::client::{Client, ClientBuilder};
7//! use tokio::net::TcpStream;
8//! use tokio::sync::mpsc::channel;
9//! use std::error::Error;
10//!
11//! async fn connect() -> Result<Client, Box<dyn Error>> {
12//!   Client::connect(
13//!       ClientBuilder::new("127.0.0.1:61613")
14//!   ).await
15//! }
16//! ```
17//!
18//! Emitting a new frame:
19//!
20//! ```no_run
21//! use stomp_rs::protocol::frame::Send;
22//! use stomp_rs::client::Client;
23//! use std::error::Error;;
24//!
25//! async fn send_example(client: &Client) -> Result<(), Box<dyn Error>> {
26//!   client.send(
27//!       Send::new("/topic/test")
28//!         .body("test-message")
29//!   ).await
30//! }
31//! ```
32//!
33//! Subscribe:
34//! ```no_run
35//! use stomp_rs::client::Client;
36//! use stomp_rs::protocol::frame::Subscribe;
37//! use tokio::sync::mpsc::{channel, Sender, Receiver};
38//! use std::error::Error;
39//! use stomp_rs::protocol::{Frame, ServerCommand};
40//! use std::future::Future;
41//! use std::sync::Arc;
42//!
43//! async fn subscribe_example(client: Arc<Client>)-> Result<(), Box<dyn Error>> {
44//!   let (sender, mut receiver): (Sender<Frame<ServerCommand>>, Receiver<Frame<ServerCommand>>) = channel(16);
45//!
46//!   let subscriber_client = Arc::clone(&client);
47//!   tokio::spawn(async move {
48//!     match receiver.recv().await {
49//!       Some(frame) => {
50//!         /* process frame */
51//!
52//!         // Send ack to server
53//!         subscriber_client.ack(frame.ack().unwrap())
54//!             .await;
55//!       }
56//!       None => { }
57//!     }
58//!   });
59//!
60//!   client.subscribe(
61//!       Subscribe::new_with_random_id("/topic/test"),
62//!       sender
63//!   ).await
64//! }
65pub mod client;
66pub mod connection;
67pub mod protocol;