Crate dove[][src]

Dove is an open source Rust implementation of the AMQP 1.0 OASIS standard (http://www.amqp.org/). The Advanced Message Queuing Protocol (AMQP) is an open standard for passing business messages between applications or organizations. It connects systems, feeds business processes with the information they need and reliably transmits onward the instructions that achieve their goals.

Dove aims to be an AMQP 1.0 implementation with the following properties:

Low footprint - efficient memory usage and pay only for what you use. Portable - minimize the number of dependencies and use portable APIs. The library supports only the basics right now: Establishing connections, creating sessions, links and sending and receiving message. Most AMQP 1.0 types have been implemented, and conversion for many Rust native types exists. Support for SASL ANONYMOUS and PLAIN.

Dove exposes two different APIs:

  • An API for writing messaging applications using async rust.
  • A low level connection API that allows you to send and receive frames defined as rust types.

Example

use dove::container::*;
use futures::executor::block_on;
use testcontainers::{clients, images, Docker};
env_logger::init();

// Start a broker that we can run the client against.
let docker = clients::Cli::default();
let node = docker.run(
    images::generic::GenericImage::new("docker.io/vromero/activemq-artemis:2-latest")
        .with_env_var("ARTEMIS_USERNAME", "test")
        .with_env_var("ARTEMIS_PASSWORD", "test")
);
std::thread::sleep(std::time::Duration::from_millis(30000));
let port: u16 = node.get_host_port(5672).unwrap();

// Create client and connect
let container = Container::new()
    .expect("unable to create container")
    .start();

// connect creates the TCP connection and sends OPEN frame.
block_on(async {
    let connection = container
        .connect("localhost", port, ConnectionOptions::new()
            .sasl_mechanism(SaslMechanism::Plain)
            .username("test")
            .password("test"))
        .await
        .expect("connection not created");

    // new_session creates the AMQP session.
    let session = connection
        .new_session(None)
        .await
        .expect("session not created");

    // Create receiver
    let receiver = session
        .new_receiver("queue1")
        .await
        .expect("receiver not created");

    // Create sender
    let sender = session
        .new_sender("queue1")
        .await
        .expect("sender not created");

    //  Send message and get delivery.
    let message = Message::amqp_value(Value::String("Hello, World".to_string()));
    let _ = sender.send(message).await.expect("delivery not received");

    // Receive message. Disposition will be sent in destructor of delivery.
    let delivery = receiver.receive().await.expect("unable to receive message");

    println!("Received: {:?}", delivery.message().body);

});

Modules

conn

The conn module contains basic primitives for establishing and accepting AMQP connections and performing the initial handshake. Once handshake is complete, the connection can be used to send and receive frames.

container

The container module contains a simple API for creating client connections and sending and receiving messages

convert

Conversion functions for types that is used in this implementation. This is used * when decoding frames. At present there is a lot of duplication, and this part * could use some refactoring to simplify. *

decoding

The decoding module contains AMQP 1.0 type decoders and rust native type decoders.

driver

The driver module is an intermediate layer with the core logic for interacting with different AMQP 1.0 endpoint entities (connections, sessions, links).

encoding

The encoding module contains AMQP 1.0 type encoders and rust native types encoders.

error

The error module implements all AMQP 1.0 error types that is supported by dove. Conversion from many different error types are supported.

frame_codec

The frame_codec contains utility types for simplifying frame and composite type encoding and decoding.

framing

The framing module implements the different AMQP 1.0 frame type model, encoder and decoder.

message

The message module implements the AMQP 1.0 message format encoding and decoding.

sasl

The sasl module implements the SASL support in dove.

symbol

The symbol module contains symbol type specific code.

transport

The transport module contains the network connectivity transport for the upper layers. It is implemented using mio.

types

The types module contains the AMQP 1.0 types system encoders and decoders. By using these types you can enforce a certain encoding for your data.

url

Utility module for working with AMQP 1.0 URLs similar to that supported by Apache Qpid.