Giter Club home page Giter Club logo

wamp_async's Introduction

wamp_async

crates.io mio Lines of Code

An asynchronous WAMP client implementation written in rust.

Usage

For usage examples, see :

  • Publisher/Subscriber

    // Publish event with no arguments and with acknowledgment
    let ack_id = client.publish("peer.heartbeat", None, None, true).await?;
    println!("Ack id {}", ack_id.unwrap());
    // Register for events
    let (_sub_id, mut event_queue) = client.subscribe("peer.heartbeat").await?;
    // Wait for the next event
    match event_queue.recv().await {
        Some((_pub_id, args, kwargs)) => println!("Event(args: {:?}, kwargs: {:?})", args, kwargs),
        None => println!("Event queue closed"),
    };
  • RPC caller & callee

    // Call endpoint with one argument
    let (args, kwargs) = client.call("peer.echo", Some(vec![12.into()]), None).await?;
    println!("RPC returned {:?} {:?}", args, kwargs);
    // Declare your RPC function
    async fn rpc_echo(args: Option<WampArgs>, kwargs: Option<WampKwArgs>) -> Result<(Option<WampArgs>, Option<WampKwArgs>), WampError> {
        println!("peer.echo {:?} {:?}", args, kwargs);
        Ok((args, kwargs))
    }
    
    // Register the function
    let rpc_id = client.register("peer.echo", rpc_echo).await?;

Structs Serialization and Deserialization

// Call endpoint with one argument
let (args, kwargs) = client.call("peer.echo", Some(vec![12.into()]), None).await?;
// or
let (args, kwargs) = client.call("peer.echo", Some(wamp_async::try_into_args((12,))), None).await?;
println!("RPC returned {:?} {:?}", args, kwargs);
#[derive(serde::Deserialize, serde::Serialize)]
struct MyKwArgs {
    name: String,
}

// Declare your RPC function
async fn rpc_echo(args: Option<WampArgs>, kwargs: Option<WampKwArgs>) -> Result<(Option<WampArgs>, Option<WampKwArgs>), WampError> {
    // You only need serde-deserializable structure (e.g. a tuple of two integers)
    let valid_args: (i32, i32) = if let Some(args) = args {
        wamp_async::try_from_args(args)?
    } else {
        return Err(wamp_async::WampError::UnknownError("positional args are required".to_string()));
    };
    println!("Two integers are: {}, {}", valid_args.0, valid_args.1);

    // You can also use a custom struct and use a little bit of Rust helpers
    let valid_kwargs: Option<MyKwArgs> = kwargs.map(wamp_async::try_from_kwargs).transpose()?;

    if let Some(MyKwArgs { name }) = valid_kwargs {
        println!("Name is {}", name);
    } else {
        println!("There were no kwargs specified");
    }

    Ok((
        Some(wamp_async::try_into_args(valid_args)?),
        valid_kwargs.map(wamp_async::try_into_kwargs).transpose()?,
    ))
}

// Register the function
let rpc_id = client.register("peer.echo", rpc_echo).await?;

Features

Feature Desciption Status
Websocket Use websocket as the transport
Secure Websocket Websocket over HTTPS
RawSocket Use lightweight TCP as the transport
Secure RawSocket RawSocket with TLS
MsgPack Use MessagePack for message serialization
JSON Uses JSON for message serialization

Client

Basic profile :

Feature Desciption Status
Publisher Ability to publish messages on topics
Subscriber Can subscribe and receive events for a topic
Caller Ability to call RPC endpoints
Callee Ability to register RPC endpoints

Advanced profile:

Feature Desciption Status
Client Authentication Low-level support for Client Authentication (Ticket-based, CRA)
Progressive Calls Partial results reported from Callee to Caller help wanted

License

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.

wamp_async's People

Contributors

elast0ny avatar frol avatar kkazuo avatar lmcgartland avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.