Skip to content

Commit bfb1d3e

Browse files
authored
Merge pull request #3894 from jooby-project/3889
tRPC: remove from core
2 parents 0f5a11d + f029537 commit bfb1d3e

File tree

134 files changed

+1566
-551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1566
-551
lines changed
Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
1-
==== gRPC
1+
== gRPC
22

33
The `jooby-grpc` module provides first-class, native support for https://grpc.io/[gRPC].
44

55
Unlike traditional setups that require spinning up a separate gRPC server on a different port (often forcing a specific transport like Netty), this module embeds the `grpc-java` engine directly into Jooby.
66

77
By using a custom native bridge, it allows you to run strictly-typed gRPC services alongside your standard REST API routes on the **exact same port**. It bypasses the standard HTTP/1.1 pipeline in favor of a highly optimized, native interceptor tailored for HTTP/2 multiplexing, reactive backpressure, and zero-copy byte framing. It works natively across Undertow, Netty, and Jetty.
88

9-
===== Usage
9+
=== Usage
1010

1111
gRPC strictly requires HTTP/2. Before installing the module, ensure your application is configured to use a supported server with HTTP/2 enabled.
1212

13-
[source, xml, role="primary"]
14-
.Maven
15-
----
16-
<dependency>
17-
<groupId>io.jooby</groupId>
18-
<artifactId>jooby-grpc</artifactId>
19-
<version>${jooby.version}</version>
20-
</dependency>
21-
----
22-
23-
[source, gradle, role="secondary"]
24-
.Gradle
25-
----
26-
implementation 'io.jooby:jooby-grpc:${jooby.version}'
27-
----
13+
[dependency, artifactId="jooby-grpc"]
14+
.
2815

2916
[source, java, role="primary"]
3017
.Java
@@ -33,16 +20,10 @@ import io.jooby.Jooby;
3320
import io.jooby.ServerOptions;
3421
import io.jooby.grpc.GrpcModule;
3522
36-
public class App extends Jooby {
37-
{
38-
setServerOptions(new ServerOptions().setHttp2(true)); // <1>
39-
40-
install(new GrpcModule( // <2>
41-
new GreeterService()
42-
));
23+
{
24+
setServerOptions(new ServerOptions().setHttp2(true)); // <1>
4325
44-
get("/api/health", ctx -> "OK"); // <3>
45-
}
26+
install(new GrpcModule(new GreeterService())); // <2>
4627
}
4728
----
4829

@@ -53,22 +34,17 @@ import io.jooby.ServerOptions
5334
import io.jooby.grpc.GrpcModule
5435
import io.jooby.kt.Kooby
5536
56-
class App : Kooby({
57-
serverOptions = ServerOptions().setHttp2(true) // <1>
58-
59-
install(GrpcModule( // <2>
60-
GreeterService()
61-
))
37+
{
38+
serverOptions = ServerOptions().setHttp2(true) // <1>
6239
63-
get("/api/health") { "OK" } // <3>
64-
})
40+
install(GrpcModule(GreeterService())) // <2>
41+
}
6542
----
6643

6744
<1> Enable HTTP/2 on your server.
6845
<2> Install the module and explicitly register your services.
69-
<3> Standard REST routes still work on the exact same port!
7046

71-
===== Dependency Injection
47+
=== Dependency Injection
7248

7349
If your gRPC services require external dependencies (like database repositories), you can register the service classes instead of pre-instantiated objects. The module will automatically provision them using your active Dependency Injection framework (e.g., Guice, Spring).
7450

@@ -79,14 +55,10 @@ import io.jooby.Jooby;
7955
import io.jooby.di.GuiceModule;
8056
import io.jooby.grpc.GrpcModule;
8157
82-
public class App extends Jooby {
83-
{
84-
install(new GuiceModule());
58+
{
59+
install(new GuiceModule());
8560
86-
install(new GrpcModule(
87-
GreeterService.class // <1>
88-
));
89-
}
61+
install(new GrpcModule(GreeterService.class)); // <1>
9062
}
9163
----
9264

@@ -97,19 +69,17 @@ import io.jooby.di.GuiceModule
9769
import io.jooby.grpc.GrpcModule
9870
import io.jooby.kt.Kooby
9971
100-
class App : Kooby({
72+
{
10173
install(GuiceModule())
10274
103-
install(GrpcModule(
104-
GreeterService::class.java // <1>
105-
))
106-
})
75+
install(GrpcModule(GreeterService::class.java)) // <1>
76+
}
10777
----
10878
<1> Pass the class references. The DI framework will instantiate them.
10979

11080
WARNING: gRPC services are registered as **Singletons**. Ensure your service implementations are thread-safe and do not hold request-scoped state in instance variables. Heavy blocking operations will safely run on background workers, protecting the native server's I/O event loops.
11181

112-
===== Server Reflection
82+
=== Server Reflection
11383

11484
If you want to use tools like `grpcurl` or Postman to interact with your services without providing the `.proto` files, you can easily enable gRPC Server Reflection.
11585

@@ -122,13 +92,11 @@ import io.grpc.protobuf.services.ProtoReflectionServiceV1;
12292
import io.jooby.Jooby;
12393
import io.jooby.grpc.GrpcModule;
12494
125-
public class App extends Jooby {
126-
{
127-
install(new GrpcModule(
128-
new GreeterService(),
129-
ProtoReflectionServiceV1.newInstance() // <1>
130-
));
131-
}
95+
{
96+
install(new GrpcModule(
97+
new GreeterService(),
98+
ProtoReflectionServiceV1.newInstance() // <1>
99+
));
132100
}
133101
----
134102

@@ -139,16 +107,16 @@ import io.grpc.protobuf.services.ProtoReflectionServiceV1
139107
import io.jooby.grpc.GrpcModule
140108
import io.jooby.kt.Kooby
141109
142-
class App : Kooby({
110+
{
143111
install(GrpcModule(
144112
GreeterService(),
145113
ProtoReflectionServiceV1.newInstance() // <1>
146114
))
147-
})
115+
}
148116
----
149117
<1> Enables the modern `v1` reflection protocol for maximum compatibility with gRPC clients.
150118

151-
===== Routing & Fallbacks
119+
=== Routing & Fallbacks
152120

153121
The gRPC module intercepts requests natively before they reach Jooby's standard router.
154122

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
==== JSON-RPC
1+
== JSON-RPC
22

33
Jooby provides full support for the JSON-RPC 2.0 specification, allowing you to build robust RPC APIs using standard Java and Kotlin controllers.
44

55
The implementation leverages Jooby's Annotation Processing Tool (APT) to generate highly optimized, reflection-free dispatchers at compile time.
66

7-
===== Usage
7+
=== Usage
8+
9+
Add dependencies:
10+
11+
[dependency, artifactId="jooby-jackson3:Jackson module, jooby-jsonrpc-jackson3:Jackson JSON-RPC implementation, jooby-jsonrpc:JSON-RPC Module"]
12+
.
813

914
To expose a JSON-RPC endpoint, annotate your controller or service with `@JsonRpc`. You can optionally provide a namespace to the annotation, which will prefix all generated method names for that class.
1015

@@ -50,61 +55,57 @@ The annotation dictates how the protocol methods are named and exposed:
5055

5156
**Mixing Annotations:** You can freely mix standard REST annotations (like `@GET`, `@POST`) and `@JsonRpc` on the same class. The APT handles this by generating two entirely separate dispatchers: one standard MVC extension (e.g., `MovieService_`) and one JSON-RPC service (e.g., `MovieServiceRpc_`). They do not interfere with each other, allowing you to expose the exact same business logic over both REST and JSON-RPC simultaneously.
5257

53-
===== Registration
58+
=== Registration
5459

5560
Register the generated `JsonRpcService` in your application using the `jsonrpc` method. You must also install a supported JSON engine.
5661

5762
.JSON-RPC
5863
[source,java,role="primary"]
5964
----
6065
import io.jooby.Jooby;
61-
import io.jooby.jackson.JacksonModule;
66+
import io.jooby.jackson.Jackson3Module;
6267
63-
public class App extends Jooby {
64-
{
65-
install(new JacksonModule()); // <1>
68+
{
69+
install(new Jackson3Module()); // <1>
6670
67-
jsonrpc(new MovieServiceRpc_()); // <2>
71+
install(new JsonRpcJackson3Module()); // <2>
6872
69-
// Alternatively, you can override the default path:
70-
// jsonrpc("/json-rpc", new MovieServiceRpc_());
71-
}
73+
install(new JsonRpcModule(new MovieServiceRpc_())); // <3>
7274
}
7375
----
7476

7577
.Kotlin
7678
[source,kotlin,role="secondary"]
7779
----
7880
import io.jooby.kt.Kooby
79-
import io.jooby.jackson.JacksonModule
81+
import io.jooby.jackson.Jackson3Module
8082
81-
class App : Kooby({
82-
83-
install(JacksonModule()) // <1>
83+
{
84+
install(Jackson3Module()) // <1>
8485
85-
jsonrpc(MovieServiceRpc_()) // <2>
86+
install(JsonRpcJackson3Module()) // <2>
8687
87-
// Custom endpoint:
88-
// jsonrpc("/json-rpc", MovieServiceRpc_())
89-
})
88+
install(JsonRpcModule(MovieServiceRpc_())) // <3>
89+
}
9090
----
9191

9292
1. Install a JSON engine
93-
2. Register the generated JSON-RPC service
93+
2. Install a JSON-RPC implementation
94+
3. Register the generated JSON-RPC service
9495

95-
===== JSON Engine Support
96+
=== JSON Engine Support
9697

9798
The JSON-RPC extension delegates payload parsing and serialization to Jooby's standard JSON modules while enforcing strict JSON-RPC 2.0 compliance (such as the mutual exclusivity of `result` and `error` fields).
9899

99100
Supported engines include:
100101

101-
* **Jackson 2** (`JacksonModule`)
102-
* **Jackson 3** (`Jackson3Module`)
103-
* **Avaje JSON-B** (`AvajeJsonbModule`)
102+
* **Jackson 2**: `JacksonModule`, `JsonRpcJackson2Module`
103+
* **Jackson 3**: `Jackson3Module`, `JsonRpcJackson3Module`
104+
* **Avaje JSON-B**: `AvajeJsonbModule`, `JsonRpcAvajeJsonbModule`
104105

105106
No additional configuration is required. The generated dispatcher automatically hooks into the installed engine using the `JsonRpcParser` and `JsonRpcDecoder` interfaces, ensuring primitive types are strictly validated and parsed.
106107

107-
===== Error Mapping
108+
=== Error Mapping
108109

109110
Jooby seamlessly bridges standard Java application exceptions and HTTP status codes into the JSON-RPC 2.0 format using the `JsonRpcErrorCode` mapping. You do not need to throw custom protocol exceptions for standard failures.
110111

@@ -123,7 +124,7 @@ When an application exception is thrown (like a `NotFoundException` with an HTTP
123124
}
124125
----
125126

126-
====== Standard Protocol Errors
127+
==== Standard Protocol Errors
127128

128129
The engine handles core JSON-RPC 2.0 protocol errors automatically, returning HTTP 200 OK with the corresponding error payload:
129130

@@ -135,7 +136,7 @@ The engine handles core JSON-RPC 2.0 protocol errors automatically, returning HT
135136

136137
Application-defined errors map standard HTTP status codes to the `-32000` to `-32099` range (e.g., an HTTP 404 maps to `-32004`, an HTTP 401 maps to `-32001`).
137138

138-
===== Batch Processing
139+
=== Batch Processing
139140

140141
Batch processing is natively supported. Clients can send an array of JSON-RPC request objects, and the dispatcher will process them and return an array of corresponding response objects.
141142

docs/asciidoc/modules/modules.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Modules are distributed as separate dependencies. Below is the catalog of offici
6262
* link:{uiVersion}/modules/rocker[Rocker]: Rocker template engine.
6363
* link:{uiVersion}/modules/thymeleaf[Thymeleaf]: Thymeleaf template engine.
6464

65+
==== Remote Procedure Calls (RPC)
66+
* link:{uiVersion}/modules/gRPC[gRPC]: A high-performance, strictly-typed protocol utilizing Protocol Buffers and HTTP/2 multiplexing. Ideal for backend-to-backend communication and polyglot microservices.
67+
* link:{uiVersion}/modules/json-rpc[json-rpc]: A lightweight, stateless, and simple JSON-encoded protocol. Excellent for rapid integrations and environments where standard JSON is preferred.
68+
* link:{uiVersion}/modules/tRPC[tRPC]: A RPC implementation that provides end-to-end type safety directly between your Java backend and TypeScript clients, without requiring intermediate build steps or code generation.
69+
6570
==== Security
6671
* link:{uiVersion}/modules/jasypt[Jasypt]: Encrypted configuration files.
6772
* link:{uiVersion}/modules/pac4j[Pac4j]: Security engine module.

0 commit comments

Comments
 (0)