You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/asciidoc/gRPC.adoc
+65-16Lines changed: 65 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,14 @@
1
-
== gRPC
1
+
====gRPC
2
2
3
3
The `jooby-grpc` module provides first-class, native support for https://grpc.io/[gRPC].
4
4
5
5
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.
6
6
7
7
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.
8
8
9
-
=== Dependency
9
+
===== Usage
10
+
11
+
gRPC strictly requires HTTP/2. Before installing the module, ensure your application is configured to use a supported server with HTTP/2 enabled.
10
12
11
13
[source, xml, role="primary"]
12
14
.Maven
@@ -24,11 +26,8 @@ By using a custom native bridge, it allows you to run strictly-typed gRPC servic
<2> Install the module and explicitly register your services.
55
69
<3> Standard REST routes still work on the exact same port!
56
70
57
-
=== Dependency Injection
71
+
===== Dependency Injection
58
72
59
73
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).
60
74
61
-
[source, java]
75
+
[source, java, role="primary"]
76
+
.Java
62
77
----
63
78
import io.jooby.Jooby;
64
79
import io.jooby.di.GuiceModule;
@@ -74,19 +89,38 @@ public class App extends Jooby {
74
89
}
75
90
}
76
91
----
92
+
93
+
[source, kotlin, role="secondary"]
94
+
.Kotlin
95
+
----
96
+
import io.jooby.di.GuiceModule
97
+
import io.jooby.grpc.GrpcModule
98
+
import io.jooby.kt.Kooby
99
+
100
+
class App : Kooby({
101
+
install(GuiceModule())
102
+
103
+
install(GrpcModule(
104
+
GreeterService::class.java // <1>
105
+
))
106
+
})
107
+
----
77
108
<1> Pass the class references. The DI framework will instantiate them.
78
109
79
110
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.
80
111
81
-
=== Server Reflection
112
+
===== Server Reflection
82
113
83
114
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.
84
115
85
116
Include the `grpc-services` dependency in your build, and register the v1 reflection service alongside your own:
Copy file name to clipboardExpand all lines: docs/asciidoc/json-rpc.adoc
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ To expose a JSON-RPC endpoint, annotate your controller or service with `@JsonRp
11
11
.JSON-RPC
12
12
[source,java,role="primary"]
13
13
----
14
-
import io.jooby.jsonrpc.JsonRpc;
14
+
import io.jooby.rpc.jsonrpc.JsonRpc;
15
15
16
16
@JsonRpc("movies")
17
17
public class MovieService {
@@ -28,7 +28,7 @@ public class MovieService {
28
28
.Kotlin
29
29
[source,kotlin,role="secondary"]
30
30
----
31
-
import io.jooby.jsonrpc.JsonRpc
31
+
import io.jooby.rpc.jsonrpc.JsonRpc
32
32
33
33
@JsonRpc("movies")
34
34
class MovieService {
@@ -41,7 +41,7 @@ class MovieService {
41
41
}
42
42
----
43
43
44
-
When the Jooby APT detects the `@JsonRpc` annotation, it generates a class ending in `Rpc_` (e.g., `MovieServiceRpc_`) that implements the `io.jooby.jsonrpc.JsonRpcService` interface.
44
+
When the Jooby APT detects the `@JsonRpc` annotation, it generates a class ending in `Rpc_` (e.g., `MovieServiceRpc_`) that implements the `io.jooby.rpc.jsonrpc.JsonRpcService` interface.
45
45
46
46
The annotation dictates how the protocol methods are named and exposed:
Copy file name to clipboardExpand all lines: docs/asciidoc/rpc.adoc
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,16 @@
1
-
=== RPC
1
+
=== Remote Procedure Calls (RPC)
2
+
3
+
While standard REST architectures focus on mapping HTTP methods to resources, Remote Procedure Call (RPC) architectures are designed around executing explicit actions or functions. RPC is often the preferred choice for strictly-typed client-server contracts, high-performance microservice communication, and scenarios where a strict resource-based REST model feels overly restrictive.
4
+
5
+
Jooby provides first-class support for several RPC protocols. You can run any of these seamlessly alongside your standard HTTP routes on the exact same server instance, sharing the same underlying thread pools and I/O event loops.
6
+
7
+
Depending on your client ecosystem and performance requirements, Jooby supports:
8
+
9
+
* **gRPC**: A high-performance, strictly-typed protocol utilizing Protocol Buffers and HTTP/2 multiplexing. Ideal for backend-to-backend communication and polyglot microservices.
10
+
* **JSON-RPC**: A lightweight, stateless, and simple JSON-encoded protocol. Excellent for rapid integrations and environments where standard JSON is preferred.
11
+
* **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.
0 commit comments