MCPcopy Index your code
hub / github.com/Antti/rust-amqp

github.com/Antti/rust-amqp @0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.1 ↗ · + Follow
85 symbols 189 edges 11 files 11 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rust-amqp Build Status Crates.io

AMQ protocol implementation in pure rust.

Note: The project is still in very early stages of development, it implements all the protocol parsing, but not all the protocol methods are wrapped/easy to use. Expect the API to be changed in the future.

What it currently can do:

  • Connect to server
  • Open/close channels
  • Declare queues/exchanges
  • All the methods from the Basic class are implemented, including get, publish, ack, nack, reject, consume. So you can send/receive messages.

Have a look at the examples in examples/ folder.

Connecting to the server & openning channel:

extern crate amqp;
use amqp::Session;

let mut session = Session::open_url("amqp://localhost//").unwrap();
let mut channel = session.open_channel(1).unwrap();

Note: This library supports TLS connections, via OpenSSL. However, this is an optional feature that is enabled by default but can be disabled at build-time (via cargo --no-default-features on the command-line, or with default-features = false in your Cargo.toml).

Declaring queue:

//The arguments come in following order:
//queue: &str, passive: bool, durable: bool, exclusive: bool, auto_delete: bool, nowait: bool, arguments: Table
let queue_declare = channel.queue_declare("my_queue_name", false, true, false, false, false, Table::new());

Publishing message:

channel.basic_publish("", "my_queue_name", true, false,
    protocol::basic::BasicProperties{ content_type: Some("text".to_string()), ..Default::default()}, (b"Hello from rust!").to_vec());

This will send message: "Hello from rust!" to the queue named "my_queue_name".

The messages have type of Vec<u8>, so if you want to send string, first you must convert it to Vec<u8>.

Known issues:

  • We don't handle frames sent to channel 0 after the session was established.
  • Asynchronous methods are not handled properly see #18.
  • There are still few places where we call unwrap, not handling error responses properly.

Missing things:

  • There's no facility to re-establish connection
  • No heartbeats support
  • Not all the amqp methods are implemented in a rust interface. You can still call them manually.

Development notes:

The methods encoding/decoding code is generated using codegen.rb & amqp-rabbitmq-0.9.1.json spec.

You need to have rustfmt installed to generate protocol.rs To generate a new spec, run:

make

To build the project and run the testsuite, use cargo:

cargo build
cargo test

Moreover, there are several source examples to show library usage, and an interactive one to quickly test the library. They can be run directly from cargo:

cargo run --example interactive

OpenSSL

On MacOS X If you have problems with OpenSSL during complication, regarding missing headers or linkage, try:

brew install openssl
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib

cargo clean
cargo test

License

Licensed under either of

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

Consumer (Interface)
(no doc) [3 implementers]
src/channel.rs
Basic (Interface)
(no doc) [1 implementers]
src/basic.rs

Core symbols most depended-on inside this repo

close
called by 10
src/channel.rs
rpc
called by 10
src/channel.rs
clone
called by 8
src/connection.rs
parse_url
called by 7
src/session.rs
read
called by 6
src/channel.rs
send_method_frame
called by 6
src/channel.rs
open_channel
called by 5
src/session.rs
queue_declare
called by 4
src/channel.rs

Shape

Method 51
Function 21
Class 7
Enum 4
Interface 2

Languages

Rust100%

Modules by API surface

src/channel.rs29 symbols
src/session.rs20 symbols
src/connection.rs11 symbols
src/basic.rs11 symbols
src/amqp_error.rs4 symbols
examples/consumer.rs4 symbols
examples/simple.rs2 symbols
examples/producer.rs2 symbols
examples/interactive.rs1 symbols
examples/exchange_bind.rs1 symbols

For agents

$ claude mcp add rust-amqp \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact