base on Spring Boot starter module for gRPC framework. # The Repo [transfer to grpc-ecosystem/grpc-spring](https://github.com/grpc-ecosystem/grpc-spring/discussions/986) **Record this moment** ![image](https://github.com/yidongnan/grpc-spring-boot-starter/assets/3163314/6f4403d7-6061-4f03-b171-6a86893629cf) ------- # gRPC Spring Boot Starter [![Build master branch](https://github.com/grpc-ecosystem/grpc-spring/workflows/Build%20master%20branch/badge.svg)](https://github.com/grpc-ecosystem/grpc-spring/actions) [![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/net.devh/grpc-spring-boot-starter.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22net.devh%22%20grpc) [![MIT License](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE) [![Crowdin](https://badges.crowdin.net/grpc-spring-boot-starter/localized.svg)](https://crowdin.com/project/grpc-spring-boot-starter) [![Client-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-client-spring-boot-autoconfigure.svg?label=Client-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-client-spring-boot-autoconfigure) [![Server-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-server-spring-boot-autoconfigure.svg?label=Server-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-server-spring-boot-autoconfigure) [![Common-Javadoc](https://www.javadoc.io/badge/net.devh/grpc-common-spring-boot.svg?label=Common-Javadoc)](https://www.javadoc.io/doc/net.devh/grpc-common-spring-boot) README: [English](README.md) | [中文](README-zh-CN.md) **Documentation:** [English](https://yidongnan.github.io/grpc-spring-boot-starter/en/) | [中文](https://yidongnan.github.io/grpc-spring-boot-starter/zh-CN/) ## Features * Automatically configures and runs the gRPC server with your `@GrpcService` implementations * Automatically creates and manages your grpc channels and stubs with `@GrpcClient` * Supports other grpc-java flavors (e.g. [Reactive gRPC (RxJava)](https://github.com/salesforce/reactive-grpc/tree/master/rx-java), [grpc-kotlin](https://github.com/grpc/grpc-kotlin), ...) * Server-side: Should work for all grpc-java flavors (`io.grpc.BindableService` based) * Client-side: Requires custom `StubFactory`s\ Currently build-in support: * grpc-java * (Please report missing ones, so we can add support for them) * Supports [Spring-Security](https://github.com/spring-projects/spring-security) * Supports [Spring Cloud](https://spring.io/projects/spring-cloud) * Server-side: Adds grpc-port information to the service registration details\ Currently natively supported: * [Consul](https://github.com/spring-cloud/spring-cloud-consul) * [Eureka](https://github.com/spring-cloud/spring-cloud-netflix) * [Nacos](https://github.com/spring-cloud-incubator/spring-cloud-alibaba) * (Please report missing ones, so we can add support for them) * Client-side: Reads the service's target addresses from spring's `DiscoveryClient` (all flavors) * Supports [Spring Sleuth](https://github.com/spring-cloud/spring-cloud-sleuth) as distributed tracing solution\ (If [brave-instrumentation-grpc](https://mvnrepository.com/artifact/io.zipkin.brave/brave-instrumentation-grpc) is present) * Supports global and custom gRPC server/client interceptors * Automatic metric support ([micrometer](https://micrometer.io/)/[actuator](https://github.com/spring-projects/spring-boot/tree/master/spring-boot-project/spring-boot-actuator) based) * Also works with (non-shaded) grpc-netty ## Versions The latest version is `2.15.0.RELEASE` it was compiled with spring-boot `2.7.16` and spring-cloud `2021.0.8` but it is also compatible with a large variety of other versions. An overview of all versions and their respective library versions can be found in our [documentation](https://yidongnan.github.io/grpc-spring-boot-starter/en/versions.html). **Note:** This project can also be used without Spring-Boot, however that requires some manual bean configuration. ## Usage ### gRPC Server + Client To add a dependency using Maven, use the following: ````xml <dependency> <groupId>net.devh</groupId> <artifactId>grpc-spring-boot-starter</artifactId> <version>2.15.0.RELEASE</version> </dependency> ```` To add a dependency using Gradle: ````gradle dependencies { implementation 'net.devh:grpc-spring-boot-starter:2.15.0.RELEASE' } ```` ### gRPC Server To add a dependency using Maven, use the following: ````xml <dependency> <groupId>net.devh</groupId> <artifactId>grpc-server-spring-boot-starter</artifactId> <version>2.15.0.RELEASE</version> </dependency> ```` To add a dependency using Gradle: ````gradle dependencies { implementation 'net.devh:grpc-server-spring-boot-starter:2.15.0.RELEASE' } ```` Annotate your server interface implementation(s) with ``@GrpcService`` ````java @GrpcService public class GrpcServerService extends GreeterGrpc.GreeterImplBase { @Override public void sayHello(HelloRequest req, StreamObserver<HelloReply> responseObserver) { HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); } } ```` By default, the grpc server will listen to port `9090`. These and other [settings](grpc-server-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/server/config/GrpcServerProperties.java) can be changed via Spring's property mechanism. The server uses the `grpc.server.` prefix. Refer to our [documentation](https://yidongnan.github.io/grpc-spring-boot-starter/) for more details. ### gRPC Client To add a dependency using Maven, use the following: ````xml <dependency> <groupId>net.devh</groupId> <artifactId>grpc-client-spring-boot-starter</artifactId> <version>2.15.0.RELEASE</version> </dependency> ```` To add a dependency using Gradle: ````gradle dependencies { compile 'net.devh:grpc-client-spring-boot-starter:2.15.0.RELEASE' } ```` Annotate a field of your grpc client stub with `@GrpcClient(serverName)` * Do not use in conjunction with `@Autowired` or `@Inject` ````java @GrpcClient("gRPC server name") private GreeterGrpc.GreeterBlockingStub greeterStub; ```` **Note:** You can use the same grpc server name for multiple channels and also different stubs (even with different interceptors). Then you can send queries to your server just like this: ````java HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build()); ```` It is possible to configure the target address for each client individually. However in some cases, you can just rely on the default configuration. You can customize the default url mapping via `NameResolver.Factory` beans. If you don't configure that bean, then the default uri will be guessed using the default scheme and the name (e.g.: `dns:/<name>`): These and other [settings](grpc-client-spring-boot-autoconfigure/src/main/java/net/devh/boot/grpc/client/config/GrpcChannelProperties.java) can be changed via Spring's property mechanism. The clients use the `grpc.client.(serverName).` prefix. Refer to our [documentation](https://yidongnan.github.io/grpc-spring-boot-starter/) for more details. ## Running with (non-shaded) grpc-netty This library supports both `grpc-netty` and `grpc-netty-shaded`. The later one might prevent conflicts with incompatible grpc-versions or conflicts between libraries that require different versions of netty. **Note:** If the shaded netty is present on the classpath, then this library will always favor it over the non-shaded grpc-netty one. You can use it with Maven like this: ````xml <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-netty</artifactId> <version>${grpcVersion}</version> </dependency> <!-- For both --> <dependency> <groupId>net.devh</groupId> <artifactId>grpc-spring-boot-starter</artifactId> <version>...</version> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> </exclusion> </exclusions> </dependency> <!-- For the server (only) --> <dependency> <groupId>net.devh</groupId> <artifactId>grpc-server-spring-boot-starter</artifactId> <version>...</version> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> </exclusion> </exclusions> </dependency> <!-- For the client (only) --> <dependency> <groupId>net.devh</groupId> <artifactId>grpc-client-spring-boot-starter</artifactId> <version>...</version> <exclusions> <exclusion> <groupId>io.grpc</groupId> <artifactId>grpc-netty-shaded</artifactId> </exclusion> </exclusions> </dependency> ```` and like this when using Gradle: ````groovy implementation "io.grpc:grpc-netty:${grpcVersion}" implementation 'net.devh:grpc-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For both implementation 'net.devh:grpc-client-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For the client (only) implementation 'net.devh:grpc-server-spring-boot-starter:...' exclude group: 'io.grpc', module: 'grpc-netty-shaded' // For the server (only) ```` ## Example-Projects Read more about our example projects [here](examples). ## Troubleshooting Refer to our [documentation](https://yidongnan.github.io/grpc-spring-boot-starter/en/trouble-shooting) for help. ## Contributing Contributions are always welcomed! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines. ", Assign "at most 3 tags" to the expected json: {"id":"3669","tags":[]} "only from the tags list I provide: [{"id":77,"name":"3d"},{"id":89,"name":"agent"},{"id":17,"name":"ai"},{"id":54,"name":"algorithm"},{"id":24,"name":"api"},{"id":44,"name":"authentication"},{"id":3,"name":"aws"},{"id":27,"name":"backend"},{"id":60,"name":"benchmark"},{"id":72,"name":"best-practices"},{"id":39,"name":"bitcoin"},{"id":37,"name":"blockchain"},{"id":1,"name":"blog"},{"id":45,"name":"bundler"},{"id":58,"name":"cache"},{"id":21,"name":"chat"},{"id":49,"name":"cicd"},{"id":4,"name":"cli"},{"id":64,"name":"cloud-native"},{"id":48,"name":"cms"},{"id":61,"name":"compiler"},{"id":68,"name":"containerization"},{"id":92,"name":"crm"},{"id":34,"name":"data"},{"id":47,"name":"database"},{"id":8,"name":"declarative-gui "},{"id":9,"name":"deploy-tool"},{"id":53,"name":"desktop-app"},{"id":6,"name":"dev-exp-lib"},{"id":59,"name":"dev-tool"},{"id":13,"name":"ecommerce"},{"id":26,"name":"editor"},{"id":66,"name":"emulator"},{"id":62,"name":"filesystem"},{"id":80,"name":"finance"},{"id":15,"name":"firmware"},{"id":73,"name":"for-fun"},{"id":2,"name":"framework"},{"id":11,"name":"frontend"},{"id":22,"name":"game"},{"id":81,"name":"game-engine "},{"id":23,"name":"graphql"},{"id":84,"name":"gui"},{"id":91,"name":"http"},{"id":5,"name":"http-client"},{"id":51,"name":"iac"},{"id":30,"name":"ide"},{"id":78,"name":"iot"},{"id":40,"name":"json"},{"id":83,"name":"julian"},{"id":38,"name":"k8s"},{"id":31,"name":"language"},{"id":10,"name":"learning-resource"},{"id":33,"name":"lib"},{"id":41,"name":"linter"},{"id":28,"name":"lms"},{"id":16,"name":"logging"},{"id":76,"name":"low-code"},{"id":90,"name":"message-queue"},{"id":42,"name":"mobile-app"},{"id":18,"name":"monitoring"},{"id":36,"name":"networking"},{"id":7,"name":"node-version"},{"id":55,"name":"nosql"},{"id":57,"name":"observability"},{"id":46,"name":"orm"},{"id":52,"name":"os"},{"id":14,"name":"parser"},{"id":74,"name":"react"},{"id":82,"name":"real-time"},{"id":56,"name":"robot"},{"id":65,"name":"runtime"},{"id":32,"name":"sdk"},{"id":71,"name":"search"},{"id":63,"name":"secrets"},{"id":25,"name":"security"},{"id":85,"name":"server"},{"id":86,"name":"serverless"},{"id":70,"name":"storage"},{"id":75,"name":"system-design"},{"id":79,"name":"terminal"},{"id":29,"name":"testing"},{"id":12,"name":"ui"},{"id":50,"name":"ux"},{"id":88,"name":"video"},{"id":20,"name":"web-app"},{"id":35,"name":"web-server"},{"id":43,"name":"webassembly"},{"id":69,"name":"workflow"},{"id":87,"name":"yaml"}]" returns me the "expected json"