|
3 | 3 | * Apache License Version 2.0 https://jooby.io/LICENSE.txt |
4 | 4 | * Copyright 2014 Edgar Espina |
5 | 5 | */ |
6 | | -/** GraphQL module. */ |
| 6 | + |
| 7 | +import org.slf4j.bridge.SLF4JBridgeHandler; |
| 8 | + |
| 9 | +/** |
| 10 | + * Native gRPC extension for Jooby. |
| 11 | + * |
| 12 | + * <p>This module allows you to run strictly-typed gRPC services alongside standard Jooby HTTP |
| 13 | + * routes on the exact same port. It completely bypasses standard HTTP/1.1 pipelines in favor of a |
| 14 | + * highly optimized, reactive, native interceptor tailored for HTTP/2 multiplexing and trailing |
| 15 | + * headers. |
| 16 | + * |
| 17 | + * <h3>Usage</h3> |
| 18 | + * |
| 19 | + * <p>gRPC requires HTTP/2. Ensure your Jooby application is configured to use a supported server |
| 20 | + * with HTTP/2 enabled. |
| 21 | + * |
| 22 | + * <pre>{@code |
| 23 | + * import io.jooby.Jooby; |
| 24 | + * import io.jooby.ServerOptions; |
| 25 | + * import io.jooby.grpc.GrpcModule; |
| 26 | + * * public class App extends Jooby { |
| 27 | + * { |
| 28 | + * setServerOptions(new ServerOptions().setHttp2(true).setSecurePort(8443)); |
| 29 | + * * // Install the extension and register your services |
| 30 | + * install(new GrpcModule(new GreeterService())); |
| 31 | + * } |
| 32 | + * } |
| 33 | + * }</pre> |
| 34 | + * |
| 35 | + * <h3>Dependency Injection</h3> |
| 36 | + * |
| 37 | + * <p>If your gRPC services require external dependencies (like repositories or configuration), you |
| 38 | + * can register the service classes instead of instances. The module will automatically provision |
| 39 | + * them using Jooby's DI registry (e.g., Guice, Spring) during the application startup phase. |
| 40 | + * |
| 41 | + * <pre>{@code |
| 42 | + * public class App extends Jooby { |
| 43 | + * { |
| 44 | + * install(new GuiceModule()); |
| 45 | + * * // Pass the class reference. Guice will instantiate it! |
| 46 | + * install(new GrpcModule(GreeterService.class)); |
| 47 | + * } |
| 48 | + * } |
| 49 | + * }</pre> |
| 50 | + * |
| 51 | + * * |
| 52 | + * |
| 53 | + * <p><strong>Note:</strong> gRPC services are inherently registered as Singletons. Ensure your |
| 54 | + * service implementations are thread-safe and do not hold request-scoped state in instance |
| 55 | + * variables. |
| 56 | + * |
| 57 | + * <h3>Logging</h3> |
| 58 | + * |
| 59 | + * <p>gRPC internally uses {@code java.util.logging}. This module automatically installs the {@link |
| 60 | + * SLF4JBridgeHandler} to redirect all internal gRPC logs to your configured SLF4J backend. |
| 61 | + */ |
7 | 62 | module io.jooby.grpc { |
8 | 63 | exports io.jooby.grpc; |
9 | 64 |
|
|
0 commit comments