Skip to content

Commit

Permalink
Auto mapping google.api.http (#29)
Browse files Browse the repository at this point in the history
* just hold

* Refactor JsonTranscoderRouterFunction

* Rename to TranscodingRouterFunction

* Keep goging

* Add processUnaryCall method

* Refactor GrpcUtil

* Add some test code

* Upgrade SB 3.3.0

* Fixes tests

* Fixed spotbugs

* Almost done

* Error handling

* Cancel call

* Change the way to copy githooks

* feat: keep goging ERP-9588

* Refactor

* Keep going

* Change class name to HeaderConverter

* Change method name

* Change base package to grpcstarter

* GrpcService alias for Component

* see Component#value()

* Refactor

* Refactor

* Add transcoding webmvc/webflux

* Use IdentityHashMap

* Update application-grpc-starter-test-example.yml

* Optimize test extension

* Add T2

* rename to transcoding

* Almost done

* Add comment

* server stream supports non Get method

* optimize build

* use api

* fix tests

* optimize examples

* optimize build

* fix githooks script

* Update readme
  • Loading branch information
DanielLiu1123 authored May 4, 2024
1 parent ec6b80b commit 593518e
Show file tree
Hide file tree
Showing 240 changed files with 2,999 additions and 2,723 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build](https://img.shields.io/github/actions/workflow/status/DanielLiu1123/grpc-starter/build.yml?branch=main)](https://github.com/DanielLiu1123/grpc-starter/actions)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.danielliu1123/grpc-starter-dependencies?versionPrefix=3.)](https://central.sonatype.com/artifact/io.github.danielliu1123/grpc-starter-dependencies)
[![Maven Central](https://img.shields.io/maven-central/v/com.freemanan/grpc-starter-dependencies?versionPrefix=2.)](https://central.sonatype.com/artifact/com.freemanan/grpc-starter-dependencies)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.danielliu1123/grpc-starter-dependencies?versionPrefix=2.)](https://central.sonatype.com/artifact/io.github.danielliu1123/grpc-starter-dependencies)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

[Documentation](https://danielliu1123.github.io/grpc-starter)
Expand Down Expand Up @@ -44,11 +44,11 @@ implementation("io.github.danielliu1123:grpc-boot-starter")
```java
@SpringBootApplication
@EnableGrpcClients("io.grpc")
public class SimpleApp extends SimpleServiceGrpc.SimpleServiceImplBase {

public static void main(String[] args) {
new SpringApplicationBuilder(SimpleApp.class)
.properties("grpc.client.base-packages=io.grpc")
.properties("grpc.client.authority=127.0.0.1:9090")
.run(args);
}
Expand Down
43 changes: 17 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
plugins {
id 'org.springframework.boot' version "${springBootVersion}" apply false
id 'io.spring.dependency-management' version "${springDependencyManagementVersion}" apply false
id "com.google.protobuf" version "${protobufGradlePluginVersion}" apply false
id 'com.diffplug.spotless' version "${spotlessVersion}" apply false
id "org.springframework.boot" version "${springBootVersion}" apply false
id "io.spring.dependency-management" version "${springDependencyManagementVersion}" apply false
id "com.diffplug.spotless" version "${spotlessVersion}" apply false
id "com.github.spotbugs" version "${spotbugsVersion}" apply false
id "build.buf" version "${bufGradlePluginVersion}" apply false
id "com.google.protobuf" version "${protobufGradlePluginVersion}" apply false
}

allprojects {
Expand All @@ -13,34 +12,33 @@ allprojects {
return
}

apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: "java"
apply plugin: "java-library"

java {
registerFeature('optionalSupport') {
registerFeature("optionalSupport") {
usingSourceSet(sourceSets.main)
}
}

repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
compileJava {
options.encoding = 'UTF-8'
options.compilerArgs << '-parameters'
options.encoding = "UTF-8"
options.compilerArgs << "-parameters"
}
compileTestJava {
options.encoding = 'UTF-8'
options.compilerArgs << '-parameters'
options.encoding = "UTF-8"
options.compilerArgs << "-parameters"
}
test {
useJUnitPlatform()
}
// dependency management
apply plugin: 'io.spring.dependency-management'
apply plugin: "io.spring.dependency-management"
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
Expand All @@ -57,9 +55,9 @@ allprojects {
compileOnly("com.github.spotbugs:spotbugs-annotations:${spotbugsAnnotationsVersion}")
}
// spotless
apply plugin: 'com.diffplug.spotless'
apply plugin: "com.diffplug.spotless"
spotless {
encoding 'UTF-8'
encoding "UTF-8"
java {
toggleOffOn()
removeUnusedImports()
Expand All @@ -69,7 +67,7 @@ allprojects {

targetExclude "build/generated/**"

custom('Refuse wildcard imports', {
custom("Refuse wildcard imports", {
if (it =~ /\nimport .*\*;/) {
throw new IllegalStateException("Do not use wildcard imports, 'spotlessApply' cannot resolve this issue, please fix it manually.")
}
Expand All @@ -78,17 +76,10 @@ allprojects {
}

// spotbugs
apply plugin: 'com.github.spotbugs'
apply plugin: "com.github.spotbugs"
spotbugs {
spotbugsTest.enabled = false
omitVisitors.addAll 'FindReturnRef', 'DontReusePublicIdentifiers'
omitVisitors.addAll "FindReturnRef", "DontReusePublicIdentifiers"
excludeFilter = file("${rootDir}/config/spotbugs/exclude.xml")
}
}

tasks.register('installGitHook', Copy) {
from "$rootProject.rootDir/.githooks"
into { new File(rootProject.rootDir, '.git/hooks') }
fileMode 0775
}
installGitHook
2 changes: 1 addition & 1 deletion docs/en-us/client/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. Add the dependency:

```groovy
implementation 'com.freemanan:grpc-client-boot-starter'
implementation 'io.github.danielliu1123:grpc-client-boot-starter'
```
2. Configure the scanning of gRPC stubs:
Expand Down
4 changes: 2 additions & 2 deletions docs/en-us/extension/json-transcoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ HTTP/JSON call methods with just one set of gRPC implementations.
1. Add Dependencies

```groovy
implementation 'com.freemanan:grpc-boot-starter'
implementation 'com.freemanan:grpc-starter-web'
implementation 'io.github.danielliu1123:grpc-boot-starter'
implementation 'io.github.danielliu1123:grpc-starter-web'
implementation 'io.grpc:grpc-testing-proto' // For demonstration purposes, using gRPC's simple service
```

Expand Down
2 changes: 1 addition & 1 deletion docs/en-us/extension/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ clients.
1. Add dependencies

```groovy
implementation("com.freemanan:grpc-starter-metrics")
implementation("io.github.danielliu1123:grpc-starter-metrics")
// Actuator uses Micrometer as the metrics collection facade, here we use Prometheus
// You can refer to the list of metric collectors supported by Micrometer at https://micrometer.io/docs/
implementation("io.micrometer:micrometer-registry-prometheus")
Expand Down
4 changes: 2 additions & 2 deletions docs/en-us/extension/protobuf-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ user
1. Add the dependency

```groovy
implementation("com.freemanan:grpc-starter-protovalidate")
implementation("io.github.danielliu1123:grpc-starter-protovalidate")
```
> In most cases, you only need the API module to depend on the `grpc-starter-protovalidate` module.
Expand Down Expand Up @@ -59,7 +59,7 @@ user
1. Add the dependency

```groovy
implementation("com.freemanan:grpc-starter-validation")
implementation("io.github.danielliu1123:grpc-starter-validation")
```
> In most cases, you only need the API module to depend on the `grpc-starter-validation` module.
Expand Down
2 changes: 1 addition & 1 deletion docs/en-us/extension/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The Test extension integrates with `SpringBootTest`.
Add the dependency:

```groovy
testImplementation("com.freemanan:grpc-starter-test")
testImplementation("io.github.danielliu1123:grpc-starter-test")
```

After adding the dependency, the gRPC server will communicate using in-process by default.
Expand Down
2 changes: 1 addition & 1 deletion docs/en-us/extension/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clients.
2. Add dependencies

```groovy
implementation("com.freemanan:grpc-starter-tracing")
implementation("io.github.danielliu1123:grpc-starter-tracing")
// You can refer to the list of tracing systems supported by Micrometer at https://micrometer.io/docs/tracing
implementation("io.micrometer:micrometer-tracing-bridge-brave")
```
Expand Down
8 changes: 4 additions & 4 deletions docs/en-us/guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#### **Gradle**

```groovy
implementation platform('com.freemanan:grpc-starter-dependencies:3.2.4')
implementation 'com.freemanan:grpc-boot-starter'
implementation platform('io.github.danielliu1123:grpc-starter-dependencies:3.2.4')
implementation 'io.github.danielliu1123:grpc-boot-starter'
```

#### **Maven**
Expand All @@ -15,7 +15,7 @@ implementation 'com.freemanan:grpc-boot-starter'
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.freemanan</groupId>
<groupId>io.github.danielliu1123</groupId>
<artifactId>grpc-starter-dependencies</artifactId>
<version>3.2.4</version>
<type>pom</type>
Expand All @@ -25,7 +25,7 @@ implementation 'com.freemanan:grpc-boot-starter'
</dependencyManagement>

<dependency>
<groupId>com.freemanan</groupId>
<groupId>io.github.danielliu1123</groupId>
<artifactId>grpc-boot-starter</artifactId>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/en-us/server/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
Add dependencies:

```groovy
implementation 'com.freemanan:grpc-server-boot-starter'
implementation 'io.github.danielliu1123:grpc-server-boot-starter'
```

or

```groovy
implementation 'com.freemanan:grpc-boot-starter'
implementation 'io.github.danielliu1123:grpc-boot-starter'
```

> `grpc-boot-starter` includes `grpc-server-boot-starter` and `grpc-client-boot-starter`.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-cn/client/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
1. 引入依赖

```groovy
implementation 'com.freemanan:grpc-client-boot-starter'
implementation 'io.github.danielliu1123:grpc-client-boot-starter'
```
2. 配置扫描 gRPC stubs
Expand Down
4 changes: 2 additions & 2 deletions docs/zh-cn/extension/json-transcoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ JSON transcoder 扩展将 gRPC 服务转换为 HTTP/JSON 服务,**_只需要
1. 添加依赖

```groovy
implementation 'com.freemanan:grpc-boot-starter'
implementation 'com.freemanan:grpc-starter-web'
implementation 'io.github.danielliu1123:grpc-boot-starter'
implementation 'io.github.danielliu1123:grpc-starter-web'
implementation 'io.grpc:grpc-testing-proto' // 为了演示,使用 gRPC 提供的 simple service
```
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-cn/extension/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Metrics 扩展了 Spring Boot Actuator,为 gRPC 服务端和客户端提供了
1. 引入依赖

```groovy
implementation("com.freemanan:grpc-starter-metrics")
implementation("io.github.danielliu1123:grpc-starter-metrics")
// Actuator 使用 Micrometer 作为指标采集门面,这里使用 Prometheus
// Micrometer 支持的指标采集器可以参考 https://micrometer.io/docs/
implementation("io.micrometer:micrometer-registry-prometheus")
Expand Down
4 changes: 2 additions & 2 deletions docs/zh-cn/extension/protobuf-validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ user
1. 添加依赖项

```groovy
implementation("com.freemanan:grpc-starter-protovalidate")
implementation("io.github.danielliu1123:grpc-starter-protovalidate")
```
> 在大多数情况下,您只需要 API 模块依赖 `grpc-starter-protovalidate` 模块。
Expand Down Expand Up @@ -57,7 +57,7 @@ user
1. 添加依赖项

```groovy
implementation("com.freemanan:grpc-starter-validation")
implementation("io.github.danielliu1123:grpc-starter-validation")
```
> 在大多数情况下,您只需要 API 模块依赖 `grpc-starter-validation` 模块。
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-cn/extension/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Test 扩展对 `SpringBootTest` 做了集成。
添加依赖:

```groovy
testImplementation("com.freemanan:grpc-starter-test")
testImplementation("io.github.danielliu1123:grpc-starter-test")
```

添加依赖后 gRPC server 默认会使用 in-process 进行通信,可以通过 `@InProcessName` 注解获取 in-process name。
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-cn/extension/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Tracing 扩展了 Spring Boot Actuator,为 gRPC 服务端和客户端提供了
2. 引入依赖

```groovy
implementation("com.freemanan:grpc-starter-tracing")
implementation("io.github.danielliu1123:grpc-starter-tracing")
// Micrometer 支持的 Tracing system 可以参考 https://micrometer.io/docs/tracing
implementation("io.micrometer:micrometer-tracing-bridge-brave")
```
Expand Down
8 changes: 4 additions & 4 deletions docs/zh-cn/guide/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#### ** Gradle **

```groovy
implementation platform('com.freemanan:grpc-starter-dependencies:3.2.4')
implementation 'com.freemanan:grpc-boot-starter'
implementation platform('io.github.danielliu1123:grpc-starter-dependencies:3.2.4')
implementation 'io.github.danielliu1123:grpc-boot-starter'
```

#### ** Maven **
Expand All @@ -16,7 +16,7 @@ implementation 'com.freemanan:grpc-boot-starter'
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.freemanan</groupId>
<groupId>io.github.danielliu1123</groupId>
<artifactId>grpc-starter-dependencies</artifactId>
<version>3.2.4</version>
<type>pom</type>
Expand All @@ -26,7 +26,7 @@ implementation 'com.freemanan:grpc-boot-starter'
</dependencyManagement>

<dependency>
<groupId>com.freemanan</groupId>
<groupId>io.github.danielliu1123</groupId>
<artifactId>grpc-boot-starter</artifactId>
</dependency>
```
Expand Down
4 changes: 2 additions & 2 deletions docs/zh-cn/server/onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
添加依赖:

```groovy
implementation 'com.freemanan:grpc-server-boot-starter'
implementation 'io.github.danielliu1123:grpc-server-boot-starter'
```

或者

```groovy
implementation 'com.freemanan:grpc-boot-starter'
implementation 'io.github.danielliu1123:grpc-boot-starter'
```

> grpc-boot-starter 包含了 grpc-server-boot-starter 和 grpc-client-boot-starter
Expand Down
8 changes: 8 additions & 0 deletions examples/grpc-sample-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ dependencies {

apply from: "${rootDir}/gradle/deploy.gradle"
apply from: "${rootDir}/gradle/protobuf.gradle"

sourceSets {
main {
proto {
srcDirs "proto"
}
}
}
23 changes: 0 additions & 23 deletions examples/grpc-sample-api/src/main/proto/sample/pet/v1/pet.proto

This file was deleted.

Loading

0 comments on commit 593518e

Please sign in to comment.