├── .gitignore
├── LICENSE
├── README.md
├── samples-client
├── Dockerfile
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── anoyi
│ │ └── grpc
│ │ └── client
│ │ ├── Application.java
│ │ └── controller
│ │ ├── V1UserController.java
│ │ ├── V2UserController.java
│ │ └── V3UserController.java
│ └── resources
│ └── application.yaml
├── samples-facade
├── README.md
├── pom.xml
└── src
│ └── main
│ └── java
│ └── com
│ └── anoyi
│ └── grpc
│ └── facade
│ ├── entity
│ ├── PetEntity.java
│ └── UserEntity.java
│ └── service
│ ├── UserServiceByFastJSON.java
│ ├── UserServiceByProtoStuff.java
│ └── UserServiceBySofaHessian.java
├── samples-server
├── Dockerfile
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── anoyi
│ │ └── grpc
│ │ └── server
│ │ ├── Application.java
│ │ ├── controller
│ │ └── V0UserController.java
│ │ └── service
│ │ ├── UserServiceByFastJSONImpl.java
│ │ ├── UserServiceByProtoStuffImpl.java
│ │ └── UserServiceBySofaHessianImpl.java
│ └── resources
│ └── application.yml
├── spring-boot-starter-grpc
├── README.md
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── com
│ │ └── anoyi
│ │ └── grpc
│ │ ├── GrpcClient.java
│ │ ├── GrpcServer.java
│ │ ├── ServerContext.java
│ │ ├── annotation
│ │ ├── GrpcService.java
│ │ └── GrpcServiceScan.java
│ │ ├── binding
│ │ └── GrpcServiceProxy.java
│ │ ├── config
│ │ ├── GrpcAutoConfiguration.java
│ │ ├── GrpcProperties.java
│ │ └── RemoteServer.java
│ │ ├── constant
│ │ ├── GrpcResponseStatus.java
│ │ └── SerializeType.java
│ │ ├── exception
│ │ ├── GrpcException.java
│ │ └── GrpcResponseException.java
│ │ ├── service
│ │ ├── CommonService.java
│ │ ├── GrpcRequest.java
│ │ ├── GrpcResponse.java
│ │ ├── SerializeService.java
│ │ └── impl
│ │ │ ├── FastJSONSerializeService.java
│ │ │ ├── ProtoStuffSerializeService.java
│ │ │ └── SofaHessianSerializeService.java
│ │ └── util
│ │ ├── ClassNameUtils.java
│ │ ├── ProtobufUtils.java
│ │ └── SerializeUtils.java
│ ├── proto
│ └── service.proto
│ └── resources
│ └── META-INF
│ ├── spring-configuration-metadata.json
│ └── spring.factories
├── stack.yml
└── test
├── README.md
├── pom.xml
└── src
└── test
└── com.anoyi.grpc.test
├── V0LocalTest.scala
├── V1SofaHessianTest.scala
├── V2ProtoStuffTest.scala
└── V3FastJsonTest.scala
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 |
3 | */**/target
4 |
5 | */**/*.iml
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Anoyi
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 轻量级 RPC 框架
2 |
3 | Spring Boot 快速集成 gRPC,轻松实现远程方法调用。
4 |
5 | 
6 |
7 | ### 使用文档
8 |
9 | [新人入门文档](https://github.com/ChinaSilence/spring-boot-starter-grpc/wiki)
10 |
11 | ### 版本信息
12 |
13 | 名称|版本
14 | --|--
15 | grpc-java|1.33.1
16 | spring-boot|2.4.0.RELEASE
17 | sofa-hessian|3.3.12
18 | fastjson|1.2.75
19 |
--------------------------------------------------------------------------------
/samples-client/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM registry.cn-hangzhou.aliyuncs.com/micro-java/openjdk:8-jre-alpine
2 | MAINTAINER yangyuandong@tezign.com
3 | ENV TZ="Asia/Shanghai" HOME="/root" JVM_PARAMS=" " SPRING_PARAMS=" "
4 | WORKDIR ${HOME}
5 | ADD target/*.jar ${HOME}/ROOT.jar
6 | EXPOSE 8081
7 | CMD java $JVM_PARAMS -Djava.security.egd=file:/dev/./urandom -jar ${HOME}/ROOT.jar $SPRING_PARAMS
--------------------------------------------------------------------------------
/samples-client/README.md:
--------------------------------------------------------------------------------
1 | ### 构建镜像
2 |
3 | 1、修改 src/main/resources/application.yaml 文件为:
4 | ```
5 | server:
6 | port: 8081
7 |
8 | spring:
9 | grpc:
10 | remote-servers:
11 | - server: user
12 | host: server
13 | port: 6565
14 | ```
15 |
16 | 2、Maven 打包
17 | ```
18 | mvn clean package
19 | ```
20 |
21 | 3、构建 Docker 镜像
22 | ```
23 | docker build -t client .
24 | ```
--------------------------------------------------------------------------------
/samples-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 |
8 | org.springframework.boot
9 | spring-boot-starter-parent
10 | 2.4.0
11 |
12 |
13 | com.anoyi.grpc
14 | samples-client
15 | 1.0-SNAPSHOT
16 |
17 |
18 |
19 |
20 | org.springframework.boot
21 | spring-boot-starter-web
22 |
23 |
24 | org.springframework.boot
25 | spring-boot-starter-logging
26 |
27 |
28 |
29 |
30 |
31 |
32 | org.springframework.boot
33 | spring-boot-starter-log4j2
34 |
35 |
36 |
37 |
38 | com.anoyi.grpc
39 | samples-facade
40 | 1.0-SNAPSHOT
41 |
42 |
43 |
44 |
45 | com.anoyi
46 | spring-boot-starter-grpc
47 | 2.4.0
48 |
49 |
50 |
51 | org.projectlombok
52 | lombok
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/samples-client/src/main/java/com/anoyi/grpc/client/Application.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.client;
2 |
3 | import com.anoyi.grpc.annotation.GrpcServiceScan;
4 | import org.springframework.boot.SpringApplication;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 |
7 | @SpringBootApplication
8 | @GrpcServiceScan(packages = {"com.anoyi.grpc.facade"})
9 | public class Application {
10 |
11 | public static void main(String[] args) {
12 | SpringApplication.run(Application.class, args);
13 | }
14 |
15 | }
--------------------------------------------------------------------------------
/samples-client/src/main/java/com/anoyi/grpc/client/controller/V1UserController.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.client.controller;
2 |
3 | import com.anoyi.grpc.facade.entity.UserEntity;
4 | import com.anoyi.grpc.facade.service.UserServiceBySofaHessian;
5 | import lombok.AllArgsConstructor;
6 | import org.springframework.web.bind.annotation.*;
7 |
8 | import java.util.List;
9 |
10 | @RestController
11 | @AllArgsConstructor
12 | @RequestMapping("/v1/user")
13 | public class V1UserController {
14 |
15 | private final UserServiceBySofaHessian userServiceBySofaHessian;
16 |
17 | @PostMapping("/add")
18 | public UserEntity insertUser(@RequestBody UserEntity userEntity){
19 | userServiceBySofaHessian.insert(userEntity);
20 | return userEntity;
21 | }
22 |
23 | @GetMapping("/list")
24 | public List findAllUser(){
25 | return userServiceBySofaHessian.findAll();
26 | }
27 |
28 | @PostMapping("/remove")
29 | public String removeUser(@RequestParam("id") Long id){
30 | userServiceBySofaHessian.deleteById(id);
31 | return "success";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/samples-client/src/main/java/com/anoyi/grpc/client/controller/V2UserController.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.client.controller;
2 |
3 | import com.anoyi.grpc.facade.entity.UserEntity;
4 | import com.anoyi.grpc.facade.service.UserServiceByProtoStuff;
5 | import lombok.AllArgsConstructor;
6 | import org.springframework.web.bind.annotation.*;
7 |
8 | import java.util.List;
9 |
10 | @RestController
11 | @AllArgsConstructor
12 | @RequestMapping("/v2/user")
13 | public class V2UserController {
14 |
15 | private final UserServiceByProtoStuff userServiceByProtoStuff;
16 |
17 | @PostMapping("/add")
18 | public UserEntity insertUser(@RequestBody UserEntity userEntity){
19 | userServiceByProtoStuff.insert(userEntity);
20 | return userEntity;
21 | }
22 |
23 | @GetMapping("/list")
24 | public List findAllUser(){
25 | return userServiceByProtoStuff.findAll();
26 | }
27 |
28 | @PostMapping("/remove")
29 | public String removeUser(@RequestParam("id") Long id){
30 | userServiceByProtoStuff.deleteById(id);
31 | return "success";
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/samples-client/src/main/java/com/anoyi/grpc/client/controller/V3UserController.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.client.controller;
2 |
3 | import com.alibaba.fastjson.JSONObject;
4 | import com.anoyi.grpc.facade.entity.UserEntity;
5 | import com.anoyi.grpc.facade.service.UserServiceByFastJSON;
6 | import lombok.AllArgsConstructor;
7 | import org.springframework.web.bind.annotation.*;
8 |
9 | import java.util.List;
10 |
11 | @RestController
12 | @AllArgsConstructor
13 | @RequestMapping("/v3/user")
14 | public class V3UserController {
15 |
16 | private final UserServiceByFastJSON userServiceByFastJSON;
17 |
18 | @PostMapping("/add")
19 | public UserEntity insertUser(@RequestBody UserEntity userEntity){
20 | userServiceByFastJSON.insert(JSONObject.toJSONString(userEntity));
21 | return userEntity;
22 | }
23 |
24 | @GetMapping("/list")
25 | public List findAllUser(){
26 | return userServiceByFastJSON.findAll();
27 | }
28 |
29 | @PostMapping("/remove")
30 | public String removeUser(@RequestParam("id") Long id){
31 | userServiceByFastJSON.deleteById(String.valueOf(id));
32 | return "success";
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/samples-client/src/main/resources/application.yaml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 |
4 | spring:
5 | grpc:
6 | remote-servers:
7 | - server: user
8 | host: 127.0.0.1
9 | port: 6565
10 |
--------------------------------------------------------------------------------
/samples-facade/README.md:
--------------------------------------------------------------------------------
1 | ### 安装到本地 Maven 仓库
2 |
3 | 1、Maven Install
4 | ```
5 | mvn clean install
6 | ```
--------------------------------------------------------------------------------
/samples-facade/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.anoyi.grpc
8 | samples-facade
9 | 1.0-SNAPSHOT
10 |
11 |
12 |
13 |
14 | com.anoyi
15 | spring-boot-starter-grpc
16 | 2.4.0
17 | provided
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/samples-facade/src/main/java/com/anoyi/grpc/facade/entity/PetEntity.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.facade.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 |
7 | /**
8 | * 宠物
9 | */
10 | @Data
11 | public class PetEntity implements Serializable {
12 |
13 | private static final long serialVersionUID = 0L;
14 |
15 | private String type;
16 |
17 | private String name;
18 |
19 | private UserEntity owner;
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/samples-facade/src/main/java/com/anoyi/grpc/facade/entity/UserEntity.java:
--------------------------------------------------------------------------------
1 | package com.anoyi.grpc.facade.entity;
2 |
3 | import lombok.Data;
4 |
5 | import java.io.Serializable;
6 | import java.util.List;
7 | import java.util.Map;
8 |
9 | /**
10 | * 人物
11 | */
12 | @Data
13 | public class UserEntity implements Serializable {
14 |
15 | private static final long serialVersionUID = 0L;
16 |
17 | private Long id;
18 |
19 | private String name;
20 |
21 | private int age;
22 |
23 | private String gender;
24 |
25 | private Map scores;
26 |
27 | private UserEntity friend;
28 |
29 | private PetEntity pet;
30 |
31 | private List