Giter Site home page Giter Site logo

rxrpc's Introduction

RxRpc: End-to-end asynchronus ReactiveX-based RPC framework for Java and TypeScript

Tag Build Status Download npm version

WORK IN PROGRESS...

Goal

To provide easy-to-use asynchronous RPC framework, oriented for Java backend and Java/TypeScript client

Features:
  • Fully asynchronous (both client and server side)
  • Automated client code generation for Java and TypeScript
  • Custom dependency injection framework support
  • WebSockets support

Getting started

Server side

Endpoint definition:

Endpoint is defined by class, annotated with @RxRpcEndpoint annotation. Each RPC method is annotated with @RxRpcMethod

Return types:

Following return types are allowed:

  • Asynchronous types
    • Observable<T>
    • Single<T>
    • Maybe<T>
    • Completable
    • Publisher<T>
    • Future<T>
  • Any other type will be handled as synchronous (from server side) invocation

Endpoint definition example

@RxRpcEndpoint
public interface SayHelloEndpoint {
    @RxRpcMethod
    Observable<String> sayHello(String name);
}

public class SayHelloEndpointImpl implements SayHelloEndpoint {
    public Observable<String> sayHello(String name) {
        Observable.just("Hello, " + name).delay(2, TimeUnit.SECONDS);
    }
}

Jetty-based embedded server, serving the endpoint, defined above

public class SampleServer {
    private final Server jetty;
    private final JettyWebSocketRxTransport.Server transportServer = JettyWebSocketRxTransport
            .builder()
            .buildServer();
            
    private final RxServer rxServer;

    public SampleServer(int port) {
        this.jetty = createJetty(port);
        this.rxServer = RxServer.configBuilder()
                .server(transportServer) // Use jetty WebSocket-servlet based transport
                .discoverModules()       // Discover auto-generated endpoint modules
                .resolver(ServiceResolvers
                        .builder()
                        .bind(SayHelloEndpoint.class).to(SayHelloEndpointImpl.class)
                        .build())
                .createServer();
    }

    public void start() throws Exception {
        this.jetty.start();
        this.rxServer.start();
    }

    public void stop() throws Exception {
        this.rxServer.stop();
        this.jetty.stop();
    }

    public void join() throws InterruptedException {
        this.jetty.join();
    }

    private Server createJetty(int port) {
        Server jetty = new Server(port);
        ServletContextHandler context = new ServletContextHandler();
        context.setContextPath("/");
        ServletHolder servletHolder = new ServletHolder(transportServer);
        context.addServlet(servletHolder, "/api/");
        jetty.setHandler(context);
        return jetty;
    }
}

Client side

Java client example

    RxClient rxClient = RxClient.forClient(JettyWebSocketRxTransport.builder().buildClient());
    SayHelloEndpoint sayHelloClient = rxClient.connect(uri).resolve(SayHelloEndpoint_RxClient.class);
    sayHelloClient
            .sayHello("Alice")
            .test()
            .awaitDone(1000, TimeUnit.MILLISECONDS)
            .assertValueCount(1)
            .assertValue("Hello, Alice");

Component diagram

Diagram

rxrpc's People

Contributors

assafkm avatar bulanan avatar denis-itskovich avatar dicbrus avatar dmitrybrus avatar haimshalev avatar okaminer avatar urikoa avatar

Watchers

 avatar  avatar  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.