rxrpc / rxrpc-jetty-websocket

General purpose utils / module: rxrpc-jetty-websocket

License

License

Categories

Categories

Jetty Container Application Servers
GroupId

GroupId

com.slimgears.rxrpc
ArtifactId

ArtifactId

rxrpc-jetty-websocket
Last Version

Last Version

0.7.23
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

rxrpc / rxrpc-jetty-websocket
General purpose utils / module: rxrpc-jetty-websocket
Project URL

Project URL

https://github.com/slim-gears/rxrpc
Source Code Management

Source Code Management

https://github.com/slim-gears/rxrpc

Download rxrpc-jetty-websocket

Dependencies

compile (7)

Group / Artifact Type Version
com.slimgears.rxrpc : rxrpc-core jar 0.7.23
org.slf4j : slf4j-api jar 1.7.30
io.reactivex.rxjava2 : rxjava jar 2.2.21
com.slimgears.utils : stream-utils jar 0.7.42
com.slimgears.utils : rx-utils jar 0.7.42
org.eclipse.jetty.websocket : websocket-server jar 9.4.36.v20210114
org.eclipse.jetty.websocket : websocket-client jar 9.4.36.v20210114

Project Modules

There are no modules declared in this project.

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

com.slimgears.rxrpc

Versions

Version
0.7.23
0.7.15-4