• Stars
    star
    205
  • Rank 191,264 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

RSocket Rust Implementation using Tokio

rsocket-rust

GitHub Workflow Status Build Status Crates.io Crates.io License GitHub Release

rsocket-rust is an implementation of the RSocket protocol in Rust(1.39+). It's an alpha version and still under active development. Do not use it in a production environment!

Example

Here are some example codes which show how RSocket works in Rust.

Dependencies

Add dependencies in your Cargo.toml.

[dependencies]
tokio = "1.0.3"
rsocket_rust = "0.7"

# add transport dependencies:
# rsocket_rust_transport_tcp = "0.7"
# rsocket_rust_transport_websocket = "0.7"

Server

extern crate log;

use futures::executor::block_on;
use rsocket_rust::prelude::*;
use rsocket_rust::utils::EchoRSocket;
use rsocket_rust::Result;
use rsocket_rust_transport_tcp::*;

#[tokio::main]
async fn main() -> Result<()> {
    env_logger::builder().format_timestamp_millis().init();

    RSocketFactory::receive()
        .transport(TcpServerTransport::from("127.0.0.1:7979"))
        .acceptor(Box::new(|setup, _sending_socket| {
            info!("incoming socket: setup={:?}", setup);
            Ok(Box::new(block_on(async move {
                RSocketFactory::connect()
                    .transport(TcpClientTransport::from("127.0.0.1:7878"))
                    .acceptor(Box::new(|| Box::new(EchoRSocket)))
                    .setup(Payload::from("I'm Rust!"))
                    .start()
                    .await
                    .unwrap()
            })))
        }))
        .serve()
        .await
}

Client

extern crate log;

use rsocket_rust::prelude::*;
use rsocket_rust::utils::EchoRSocket;
use rsocket_rust::Result;
use rsocket_rust_transport_tcp::TcpClientTransport;

#[tokio::main]
async fn main() -> Result<()> {
     env_logger::builder().format_timestamp_millis().init();
    let client = RSocketFactory::connect()
        .transport(TcpClientTransport::from("127.0.0.1:7878"))
        .acceptor(Box::new(|| {
            // Return a responder.
            Box::new(EchoRSocket)
        }))
        .start()
        .await
        .expect("Connect failed!");

    let req = Payload::builder().set_data_utf8("Ping!").build();

    match client.request_response(req).await {
        Ok(res) => info!("{:?}", res),
        Err(e) => error!("{}", e),
    }

    Ok(())
}

Implement RSocket trait

Example for access Redis(crates):

NOTICE: add dependency in Cargo.toml => redis = { version = "0.19.0", features = [ "aio" ] }

use std::str::FromStr;

use redis::Client as RedisClient;
use rsocket_rust::async_trait;
use rsocket_rust::prelude::*;
use rsocket_rust::Result;

#[derive(Clone)]
pub struct RedisDao {
    inner: RedisClient,
}

// Create RedisDao from str.
// Example: RedisDao::from_str("redis://127.0.0.1").expect("Connect redis failed!");
impl FromStr for RedisDao {
    type Err = redis::RedisError;

    fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
        let client = redis::Client::open(s)?;
        Ok(RedisDao { inner: client })
    }
}

#[async_trait]
impl RSocket for RedisDao {
    async fn request_response(&self, req: Payload) -> Result<Option<Payload>> {
        let client = self.inner.clone();
        let mut conn = client.get_async_connection().await?;
        let value: redis::RedisResult<Option<String>> = redis::cmd("GET")
            .arg(&[req.data_utf8()])
            .query_async(&mut conn)
            .await;
        match value {
            Ok(Some(value)) => Ok(Some(Payload::builder().set_data_utf8(&value).build())),
            Ok(None) => Ok(None),
            Err(e) => Err(e.into()),
        }
    }

    async fn metadata_push(&self, _req: Payload) -> Result<()> {
        todo!()
    }

    async fn fire_and_forget(&self, _req: Payload) -> Result<()> {
        todo!()
    }

    fn request_stream(&self, _req: Payload) -> Flux<Result<Payload>> {
        todo!()
    }

    fn request_channel(&self, _reqs: Flux<Result<Payload>>) -> Flux<Result<Payload>> {
        todo!()
    }
}

TODO

  • Operations
    • METADATA_PUSH
    • REQUEST_FNF
    • REQUEST_RESPONSE
    • REQUEST_STREAM
    • REQUEST_CHANNEL
  • More Operations
    • Error
    • Cancel
    • Fragmentation
    • Resume
    • Keepalive
  • QoS
    • RequestN
    • Lease
  • Transport
    • TCP
    • Websocket
    • WASM
  • Reactor
    • ...
  • High Level APIs
    • Client
    • Server

More Repositories

1

rsocket-java

Java implementation of RSocket
Java
2,354
star
2

rsocket

RSocket Protocol Definition
1,837
star
3

rsocket-js

JavaScript implementation of RSocket
TypeScript
593
star
4

rsocket-kotlin

RSocket Kotlin multi-platform implementation
Kotlin
545
star
5

rsocket-go

rsocket-go implementation
Go
504
star
6

rsocket-cpp

C++ implementation of RSocket
C++
253
star
7

rsocket-net

.NET implementation of RSocket
C#
251
star
8

rsocket-rpc-java

Standard RSocket RPC Java Implementation
Java
172
star
9

rsocket-swift

Swift implementation of RSocket Protocol
Swift
76
star
10

rsocket-py

RSocket implementation in Python
Python
76
star
11

rsocket-cli

Command-line client for ReactiveSocket
Kotlin
71
star
12

rsocket-chrome-devtools

RSocket Chrome Dev Tools
TypeScript
42
star
13

rsocket-dart

Dart implementation of RSocket
Dart
31
star
14

rsocket-rpc-js

Standard RSocket RPC Implementation
JavaScript
29
star
15

rsocket-transport-akka

Akka TCP and WebSocket transports for RSocket
Java
28
star
16

rsocket-demo-android-java8

RSocket Android Demo
Kotlin
23
star
17

rsocket-wireshark

Wireshark Plugin for RSocket
C
19
star
18

rsocket-rpc-kotlin

Standard RSocket RPC Kotlin Implementation
Kotlin
19
star
19

rsocket-rpc-net

Standard RSocket RPC .NET Implementation
C#
17
star
20

rsocket-rpc-go

RSocket RPC Golang
Go
15
star
21

rsocket-php

RSocket PHP implementation using ReactPHP
PHP
10
star
22

rsocket-tck

Technology Compatibility Kit (TCK) for RSocket implementations
Kotlin
10
star
23

rsocket-transport-aeron

Aeron Transport for RSocket
Java
10
star
24

ewma

Exponentially Weighted Moving Average
JavaScript
10
star
25

rsocket-rb

Ruby
8
star
26

rsocket-website

rsocket.io website
MDX
7
star
27

bomberman-workshop

JavaScript
7
star
28

rsocket-jmeter

RSocket JMeter Plugin
Java
3
star
29

tsc

RSocket Technical Steering Committee (TSC)
3
star
30

rsocket-c

C implementation of RSocket
3
star
31

rsocket-tck-server

RSocket TCK Server
Kotlin
2
star
32

gradle-nebula-plugin-rsocket

Groovy
1
star
33

rsocket-artwork

RSocket Logos
1
star
34

.github

Template repository for rsocket projects, includes typical README + labels
1
star