12 releases (breaking)

0.13.0 Oct 3, 2024
0.11.0 Jun 13, 2024
0.10.0 Feb 24, 2024
0.9.0 Dec 11, 2023
0.1.2 Jul 30, 2022

#105 in WebSocket

Download history 423/week @ 2024-08-18 371/week @ 2024-08-25 656/week @ 2024-09-01 352/week @ 2024-09-08 515/week @ 2024-09-15 548/week @ 2024-09-22 1061/week @ 2024-09-29 643/week @ 2024-10-06 1036/week @ 2024-10-13 579/week @ 2024-10-20 726/week @ 2024-10-27 838/week @ 2024-11-03 827/week @ 2024-11-10 874/week @ 2024-11-17 947/week @ 2024-11-24 781/week @ 2024-12-01

3,442 downloads per month
Used in 2 crates

MIT/Apache

40KB
648 lines

fe2o3-amqp-ws

WebSocket adapter for AMQP 1.0 websocket binding

This provides a thin wrapper over tokio_tungstenite::WebSocketStream, and the wrapper performs the WebSocket handshake with the "Sec-WebSocket-Protocol" HTTP header set to "amqp".

The wrapper type WebSocketStream could also be used for non-AMQP applications; however, the user should establish websocket stream with raw tokio_tungstenite API and then wrap the stream with the wrapper by fe2o3_amqp_ws::WebSocketStream::from(ws_stream).

Feature flags

default = []
Feature Description
native-tls Enables "tokio-tungstenite/native-tls"
native-tls-vendored Enables "tokio-tungstenite/native-tls-vendored"
rustls-tls-native-roots Enables "tokio-tungstenite/rustls-tls-native-roots"
rustls-tls-webpki-roots Enables "tokio-tungstenite/rustls-tls-webpki-roots"

Example

use fe2o3_amqp::{
    types::{messaging::Outcome, primitives::Value},
    Connection, Delivery, Receiver, Sender, Session,
};
use fe2o3_amqp_ws::WebSocketStream;

#[tokio::main]
async fn main() {
    let ws_stream = WebSocketStream::connect("ws://localhost:5673")
        .await
        .unwrap();
    let mut connection = Connection::builder()
        .container_id("connection-1")
        .open_with_stream(ws_stream)
        .await
        .unwrap();
    let mut session = Session::begin(&mut connection).await.unwrap();

    let mut sender = Sender::attach(&mut session, "rust-sender-link-1", "q1")
        .await
        .unwrap();
    let mut receiver = Receiver::attach(&mut session, "rust-recver-1", "q1")
        .await
        .unwrap();

    let fut = sender.send_batchable("hello batchable AMQP").await.unwrap();

    let delivery: Delivery<Value> = receiver.recv().await.unwrap();
    receiver.accept(&delivery).await.unwrap();

    let outcome: Outcome = fut.await.unwrap();
    outcome.accepted_or_else(|state| state).unwrap(); // Handle delivery outcome

    sender.close().await.unwrap();
    receiver.close().await.unwrap();
    session.end().await.unwrap();
    connection.close().await.unwrap();
}

WebAssembly support

Experimental support for wasm32-unknown-unknown target has been added since "0.3.0" and uses a web_sys::WebSocket internally. An example of this can be found in examples/wasm32-in-browser.

License: MIT/Apache-2.0

Dependencies

~2–15MB
~215K SLoC