Skip to content

RSocket code-generation from protobuf to gRPC-like Services

License

Notifications You must be signed in to change notification settings

timemates/RSP

Repository files navigation

Maven metadata URL GitHub issues GitHub closed pull requests GitHub License

RSProto

RSProto is a framework that designed to provide ability to expose your API as RPC Services. It facilitates the creation of gRPC-like services from .proto files through code generation. The framework also provides essential core components for both server and client.

Warning
This project is experimental, be ready for bugs and possible changes.

Features

  • Gradle Plugin: .proto to RSocket code generator (both client and server).
  • Server Core (JVM only): Interceptors, Instances API and bridge between Ktor and library.
  • Client Core (JVM, Web, iOS): Metadata and basic interface-markers.

Known issues
As RSocket does not natively support client-only streaming – it's not supported by the code-generator.

Getting Started

First of all, you should have the following repository:

repositories {
    maven("https://maven.timemates.org/releases")
}

Core components

Before using builtin generation from .proto to RSocket services, you should add the following dependencies:

dependencies {
    // for server
    implementation("org.timemates.rsproto:server-core:$version")
    // for client
    commonMainImplementation("org.timemates.rsproto:client-core:$version")

    // for server & client
    commonMainImplementation("org.timemates.rsproto:common-core:$version")
}

Server initialization

To configure your server, you can use ready-to-use build-bridges between Ktor and RSProto:

fun Application.configureServer() {
    routing {
        rSocketServer("/rsocket") {
            interceptor(MyInterceptor())
            service(MyService())

            instances {
                protobuf { 
                    encodeDefaults = true
                }
            }
        }
    }
}

Client initialization

Clients are generated by the code-generation Gradle plugin. To use them you need instance of rsocket and protobuf:

val apiService = TestServiceApi(rsocket, protobuf)
apiService.sayHello()

Code-generation plugin

To implement code-generation plugin in your buildscript, add the following:

plugins {
    id("org.timemates.rsproto") version "$version"
}

And use it inside your buildscript:

rsproto {
    protoSourcePath.set("src/main/proto")
    generationOutputPath.set("generated/proto-generator/src/commonMain")
    clientGeneration.set(true)
    serverGeneration.set(true)
}

Feedback

For bugs, questions and discussions please use the GitHub Issues.

License

This library is licensed under MIT License. Feel free to use, modify, and distribute it for any purpose.