Giter Club home page Giter Club logo

rsocket-deno's Introduction

RSocket Deno module

🦕Deno library to create/consume async RSocket services.

What is RSocket?

RSocket is a binary protocol for use on byte stream transports such as TCP and WebSocket. It enables the following symmetric interaction models via async message passing over a single connection:

  • request/response (stream of 1)
  • request/stream (finite stream of many)
  • fire-and-forget (no response)
  • channel (bi-directional streams)

Yes, RSocket is designed for async/reactive communication between services.

How to use?

Now RSocket Deno is under active development, please execute following command to make sure all code are updated to last version.

deno run --reload https://deno.land/x/rsocket/mod.ts

Start RSocket Server with Deno

$ deno run --allow-net https://deno.land/x/rsocket/rsocket_server.ts

and RSocket server side code as following:

import {
    RSocketServer,
    forRequestResponse,
    Payload
} from "https://deno.land/x/rsocket/mod.ts"

await RSocketServer.create(forRequestResponse(
    async (payload: Payload): Promise<Payload> => {
        console.log(`Received: ${payload.getDataUtf8()} `)
        return Payload.fromText("Hello, this is Deno Server!", "");
    })
).bind("tcp://0.0.0.0:42252");

console.log("RSocket Server started on 0.0.0.0:42252")

Start RSocket requester to test async RPC call

$ deno run --allow-net https://deno.land/x/rsocket/rsocket_client.ts

and RSocket client side code as following:

import {
    RSocketConnector,
    Payload
} from "https://deno.land/x/rsocket/mod.ts"

const rsocket = await RSocketConnector.create().connect("tcp://127.0.0.1:42252");

const result = await rsocket.requestResponse(Payload.fromText("Hello, I'm requester!", ""));
console.log(result.getDataUtf8());

Service router and stub

Service route for RSocket server side

import {
    RSocketServer,
    RSocket,
    ConnectionSetupPayload,
    RSocketRouteHandler
} from "https://deno.land/x/rsocket/mod.ts"

//RSocket Service
class UserService {

    async findNickById(id: number): Promise<string> {
        return "DenoServer";
    }
}

const server = await RSocketServer.create({
    accept(setup: ConnectionSetupPayload, sendingSocket: RSocket) {
        return RSocketRouteHandler.fromHandler("com.example.UserService", new UserService());
    }
}).bind("tcp://127.0.0.1:42252");

Service stub for requester side

import {RSocketConnector, buildServiceStub} from "https://deno.land/x/rsocket/mod.ts"

const rsocket = await RSocketConnector.create().connect("tcp://127.0.0.1:42252");

interface UserService {
    findNickById(id: number): Promise<string>;
}

const userService = buildServiceStub<UserService>(rsocket, "com.example.UserService")

let nick = await userService.findNickById(1);
console.log(nick)

WebSocket support

Just use "ws://127.0.0.0:42252" format.

Interoperate with Spring Boot RSocket

Reactive streams interoperation with RxJS

Reactive Streams supplies interoperation with RxJS, such as Publisher to Observable or Observable to Publisher.

// @deno-types="https://deno.land/x/types/rxjs/v6.5.5/rxjs.d.ts"
import {Observable, range, of} from "https://cdn.pika.dev/[email protected]";
// @deno-types="https://deno.land/x/types/rxjs/v6.5.5/operators.d.ts"
import operators from 'https://dev.jspm.io/[email protected]/operators';
const {map, filter} = operators;

import { publisherToObservable, observableToPublisher } from "https://deno.land/x/rsocket/reactivestreams/rxjs.ts"

or you can use https://deno.land/x/rxjs

import {Observable} from "https://deno.land/x/rxjs/mod.ts";
import {map, last} from "https://deno.land/x/rxjs/src/operators/index.ts";

TODO

RSocket

  • Operations
    • REQUEST_FNF
    • REQUEST_RESPONSE
    • REQUEST_STREAM
    • REQUEST_CHANNEL
    • METADATA_PUSH
  • More Operations
    • Error
    • Cancel
    • Keepalive
  • QoS
    • RequestN
    • Lease
  • Transport
    • TCP
    • Websocket
  • High Level APIs
    • Client
    • Server
  • Misc
    • RxJS

References

rsocket-deno's People

Contributors

linux-china avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rsocket-deno's Issues

[Question] How to Simply Connect and Listen?

My use Case

  • I want to connect to my asterisk AMI server (hostname, port etc)
  • Then write a message using the conn, to login
    (Both of the above can be done with Deno.connect)
  • And keep loop going to receive any messages

Question

Is this possible with your project? I've tried looking over the source but have had no luck on even connecting to the AMI , so for the time being i'm using deno.connect to connect and login, and trying to follow what you have done to. see if i can start receiving messages

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.