{"id":13439899,"url":"https://github.com/zslayton/stomp-rs","last_synced_at":"2025-03-20T09:30:54.768Z","repository":{"id":16432236,"uuid":"19183668","full_name":"zslayton/stomp-rs","owner":"zslayton","description":"A STOMP client in Rust. Compatible with RabbitMQ, ActiveMQ.","archived":false,"fork":false,"pushed_at":"2022-12-14T20:33:58.000Z","size":229,"stargazers_count":90,"open_issues_count":17,"forks_count":29,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-08T09:20:07.326Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zslayton.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-04-26T17:30:39.000Z","updated_at":"2024-07-14T11:07:06.000Z","dependencies_parsed_at":"2022-09-13T22:22:19.206Z","dependency_job_id":null,"html_url":"https://github.com/zslayton/stomp-rs","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zslayton%2Fstomp-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zslayton%2Fstomp-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zslayton%2Fstomp-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zslayton%2Fstomp-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zslayton","download_url":"https://codeload.github.com/zslayton/stomp-rs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244585668,"owners_count":20476772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:18.016Z","updated_at":"2025-03-20T09:30:54.442Z","avatar_url":"https://github.com/zslayton.png","language":"Rust","funding_links":[],"categories":["Libraries","库 Libraries","库","代码"],"sub_categories":["Network programming","网络编程 Network programming","网络编程"],"readme":"stomp-rs [![](https://api.travis-ci.org/zslayton/stomp-rs.png?branch=master)](https://travis-ci.org/zslayton/stomp-rs) [![](http://meritbadge.herokuapp.com/stomp)](https://crates.io/crates/stomp)\n=====\n\n`stomp-rs` provides a full [STOMP](http://stomp.github.io/stomp-specification-1.2.html) 1.2 client implementation for the [Rust programming language](http://www.rust-lang.org/). This allows programs written in Rust to interact with message queueing services like [ActiveMQ](http://activemq.apache.org/), [RabbitMQ](http://www.rabbitmq.com/), [HornetQ](http://hornetq.jboss.org/) and [OpenMQ](https://mq.java.net/).\n\n- [x] Connect\n- [x] Subscribe\n- [x] Send\n- [x] Acknowledge (Auto/Client/ClientIndividual)\n- [x] Transactions\n- [x] Receipts\n- [x] Disconnect\n- [x] Heartbeats\n\nThe APIs for `stomp-rs` are not yet stable and are likely to fluctuate before v1.0.\n\n## Examples\n### Connect / Subscribe / Send\n```rust\nextern crate stomp;\nuse stomp::frame::Frame;\nuse stomp::subscription::AckOrNack::Ack;\n\nfn main() {\n  \n  let destination = \"/topic/messages\";\n  let mut message_count: u64 = 0;\n\n  let mut session = match stomp::session(\"127.0.0.1\", 61613).start() {\n      Ok(session) =\u003e session,\n      Err(error)  =\u003e panic!(\"Could not connect to the server: {}\", error)\n   };\n  \n  session.subscription(destination, |frame: \u0026Frame| {\n    message_count += 1;\n    println!(\"Received message #{}:\\n{}\", message_count, frame);\n    Ack\n  }).start();\n  \n  session.message(destination, \"Animal\").send();\n  session.message(destination, \"Vegetable\").send();\n  session.message(destination, \"Mineral\").send();\n  \n  session.listen(); // Loops infinitely, awaiting messages\n\n  session.disconnect();\n}\n```\n\n### Session Configuration\n```rust\nuse stomp::header::header::Header;\nuse stomp::connection::{HeartBeat, Credentials};\n// ...\nlet mut session = match stomp::session(\"127.0.0.1\", 61613)\n  .with(Credentials(\"sullivan\", \"m1k4d0\"))\n  .with(HeartBeat(5000, 2000))\n  .with(Header::new(\"custom-client-id\", \"hmspna4\"))\n  .start() {\n      Ok(session) =\u003e session,\n      Err(error)  =\u003e panic!(\"Could not connect to the server: {}\", error)\n   };\n```\n\n### Message Configuration\n```rust\nuse stomp::header::{Header, SuppressedHeader, ContentType};\n// ...\nsession.message(destination, \"Hypoteneuse\".as_bytes())\n  .with(ContentType(\"text/plain\"))\n  .with(Header::new(\"persistent\", \"true\"))\n  .with(SuppressedHeader(\"content-length\")\n  .send();\n```\n\n### Subscription Configuration\n```rust\nuse stomp::subscription::AckMode;\nuse stomp::header::Header;\nuse stomp::frame::Frame;\n// ...\n  let id = session.subscription(destination, |frame: \u0026Frame| {\n    message_count += 1;\n    println!(\"Received message #{}:\\n{}\", message_count, frame);\n    Ack\n  })\n  .with(AckMode::Client)\n  .with(Header::new(\"custom-subscription-header\", \"lozenge\"))\n  .start();\n```\n\n### Transactions\n```rust\nmatch session.begin_transaction() {\n  Ok(mut transaction) =\u003e {\n    transaction.message(destination, \"Animal\").send();\n    transaction.message(destination, \"Vegetable\").send();\n    transaction.message(destination, \"Mineral\").send();\n    transaction.commit();\n},\n  Err(error)  =\u003e panic!(\"Could not connect to the server: {}\", error)\n};\n```\n\n### Handling RECEIPT frames\nIf you include a ReceiptHandler in your message, the client will request that the server send a receipt when it has successfully processed the frame.\n```rust\nsession.message(destination, \"text/plain\", \"Hypoteneuse\".as_bytes())\n  .with(ReceiptHandler::new(|frame: \u0026Frame| println!(\"Got a receipt for 'Hypoteneuse'.\")))\n  .send();\n```\n### Handling ERROR frames\nTo handle errors, you can register an error handler\n```rust\nsession.on_error(|frame: \u0026Frame| {\n  panic!(\"ERROR frame received:\\n{}\", frame);\n});\n```\n\n### Manipulating inbound and outbound frames\nIn some cases, brokers impose rules or restrictions which may make it necessary to\ndirectly modify frames in ways that are not conveniently exposed by the API. In such \ncases, you can use the `on_before_send` and `on_before_receive` methods to specify a\ncallback to perform this custom logic prior to the sending or receipt of each frame.\n\nFor example:\n```rust\n// Require that all NACKs include a header specifying an optional requeue policy\nsession.on_before_send(|frame: \u0026mut Frame| {\n  if frame.command == \"NACK\" {\n    frame.headers.push(Header::new(\"requeue\", \"false\"));\n  }\n});\n\nsession.on_before_receive(|frame: \u0026mut Frame| {\n  if frame.command == \"MESSAGE\" {\n    // Modify the frame\n  }\n});\n```\n### Cargo.toml\n```toml\n[package]\n\nname = \"stomp_test\"\nversion = \"0.0.1\"\nauthors = [\"your_name_here\"]\n\n[[bin]]\n\nname = \"stomp_test\"\n\n[dependencies.stomp]\n\nstomp = \"*\"\n```\n\nkeywords: `Stomp`, `Rust`, `rust-lang`, `rustlang`, `cargo`, `ActiveMQ`, `RabbitMQ`, `HornetQ`, `OpenMQ`, `Message Queue`, `MQ`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzslayton%2Fstomp-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzslayton%2Fstomp-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzslayton%2Fstomp-rs/lists"}