stomp-rs
provides a full STOMP 1.2 client implementation for the Rust programming language. This allows programs written in Rust to interact with message queueing services like ActiveMQ and RabbitMQ.
The APIs for stomp-rs
are not yet stable and are likely to fluctuate before v1.0.
```rust extern crate stomp; use stomp::frame::Frame; use stomp::subscription::AckOrNack::{self, Ack}; use stomp::subscription::AckMode::Client; use stomp::subscription::MessageHandler;
fn main() {
// Due to https://github.com/rust-lang/rust/pull/21657, // closure callbacks must be declared before 'session' is created. let mut messagecount : u64 = 0; let onmessage = |&mut: frame: &Frame| { messagecount += 1; println!("Received message #{}:\n{}", messagecount, frame); Ack }
let mut session = match stomp::connect("127.0.0.1", 61613) { Ok(session) => session, Err(error) => panic!("Could not connect to the server: {}", error) };
let destination = "/topic/messages"; let acknowledgemode = Client; session.subscribe(destination, acknowledgemode, on_message);
// Send arbitrary bytes with a specified MIME type session.sendbytes(topic, "text/plain", "Animal".asbytes());
// Send UTF-8 text with an assumed MIME type of 'text/plain' session.sendtext(topic, "Vegetable"); session.sendtext(topic, "Mineral");
session.listen(); // Loops infinitely, awaiting messages
session.disconnect(); } ```
```rust let mut tx = match session.begin_transaction() { Ok(tx) => tx, Err(error) => panic!("Could not begin new transaction: {}", error) };
tx.sendtext(topic, "Animal"); tx.sendtext(topic, "Vegetable"); tx.send_text(topic, "Mineral");
tx.commit(); // Or tx.abort(); ```
rust
session.send_text_with_receipt(topic, "Modern Major General");
debug!("Oustanding Receipt IDs: {}", session.oustanding_receipts());
```rust fn on_receipt(frame: &Frame) { debug!("RECEIPT frame received:\n{}", frame); }
session.onreceipt(onreceipt); session.sendtextwith_receipt(topic, "Modern Major General"); ```
```rust fn on_error(frame: &Frame) { panic!("ERROR frame received:\n{}", frame); }
session.onerror(onerror); ```
```toml [package]
name = "stomptest" version = "0.0.1" authors = ["yourname_here"]
[[bin]]
name = "stomp_test"
[dependencies.stomp]
stomp = "*" ```
keywords: Stomp
, Rust
, rust-lang
, rustlang
, cargo
, ActiveMQ
, RabbitMQ
, Message Queue
, MQ