Skip to content

Commit 3025853

Browse files
author
Dave Syer
committed
Autogenerate README
1 parent fe2f266 commit 3025853

File tree

5 files changed

+169
-62
lines changed

5 files changed

+169
-62
lines changed

README.md

Lines changed: 69 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,98 @@
1-
# Spring gRPC [![build status](https://github.com/spring-projects-experimental/spring-grpc/actions/workflows/deploy.yml/badge.svg)](https://github.com/spring-projects/spring-grpc/actions/workflows/deploy.yml)
1+
# Spring gRPC
2+
!["Build Status"](https://github.com/spring-projects-experimental/spring-grpc/actions/workflows/deploy.yml/badge.svg)
23

34
Welcome to the Spring gRPC project!
45

56
The Spring gRPC project provides a Spring-friendly API and abstractions for developing gRPC applications. There is a core library that makes it easy to work with gRPC and dependency injection, and a Spring Boot starter that makes it easy to get started with gRPC in a Spring Boot application (with autoconfiguration and configuration properties, for instance).
67

78
For further information go to our [Spring gRPC reference documentation](https://docs.spring.io/spring-grpc/reference/).
89

9-
## Quick Start
10+
# Getting Started
1011

11-
There is a simple sample project in the `samples` directory (e.g. [`grpc-server`](https://github.com/spring-projects-experimental/spring-grpc/tree/main/samples/grpc-server)). You can run it with `mvn spring-boot:run` or `gradle bootRun`. You will see the following code in that sample.
12+
This section offers jumping off points for how to get started using Spring gRPC. There is a simple sample project in the `samples` directory (e.g. [`grpc-server`](https://github.com/spring-projects-experimental/spring-grpc/tree/main/samples/grpc-server)). You can run it with `mvn spring-boot:run` or `gradle bootRun`. You will see the following code in that sample.
1213

13-
To create a simple gRPC server, you can use the Spring Boot starter. For Maven:
14+
You should follow the steps in each of the following section according to your needs.
15+
16+
**📌 NOTE**\
17+
Spring gRPC supports Spring Boot 3.3.x
18+
19+
## Add Milestone and Snapshot Repositories
20+
21+
If you prefer to add the dependency snippets by hand, follow the directions in the following sections.
22+
23+
To use the Milestone and Snapshot version, you need to add references to the Spring Milestone and/or Snapshot repositories in your build file.
24+
25+
For Maven, add the following repository definitions as needed (if you are using snapshots or milestones):
1426

1527
```xml
16-
<dependency>
17-
<groupId>org.springframework.grpc</groupId>
18-
<artifactId>spring-grpc-spring-boot-starter</artifactId>
19-
<version>0.1.0-SNAPSHOT</version>
20-
</dependency>
28+
<repositories>
29+
<repository>
30+
<id>spring-milestones</id>
31+
<name>Spring Milestones</name>
32+
<url>https://repo.spring.io/milestone</url>
33+
<snapshots>
34+
<enabled>false</enabled>
35+
</snapshots>
36+
</repository>
37+
<repository>
38+
<id>spring-snapshots</id>
39+
<name>Spring Snapshots</name>
40+
<url>https://repo.spring.io/snapshot</url>
41+
<releases>
42+
<enabled>false</enabled>
43+
</releases>
44+
</repository>
45+
</repositories>
2146
```
2247

23-
or for Gradle:
48+
For Gradle, add the following repository definitions as needed:
2449

2550
```groovy
26-
implementation 'org.springframework.grpc:spring-grpc-spring-boot-starter:0.1.0-SNAPSHOT'
51+
repositories {
52+
mavenCentral()
53+
maven { url 'https://repo.spring.io/milestone' }
54+
maven { url 'https://repo.spring.io/snapshot' }
55+
}
2756
```
2857

29-
For convenience, you can use the Spring gRPC BOM to manage dependencies. With Maven:
58+
## Dependency Management
59+
60+
The Spring gRPC Dependencies declares the recommended versions of all the dependencies used by a given release of Spring gRPC.
61+
Using the dependencies from your application’s build script avoids the need for you to specify and maintain the dependency versions yourself.
62+
Instead, the version you’re using determines the utilized dependency versions.
63+
It also ensures that you’re using supported and tested versions of the dependencies by default, unless you choose to override them.
64+
65+
If you’re a Maven user, you can use the dependencies by adding the following to your pom.xml file -
3066

3167
```xml
3268
<dependencyManagement>
33-
<dependencies>
34-
<dependency>
35-
<groupId>org.springframework.grpc</groupId>
36-
<artifactId>spring-grpc-dependencies</artifactId>
37-
<version>0.1.0-SNAPSHOT</version>
38-
<type>pom</type>
39-
<scope>import</scope>
40-
</dependency>
41-
</dependencies>
69+
<dependencies>
70+
<dependency>
71+
<groupId>org.springframework.ai</groupId>
72+
<artifactId>spring-grpc-dependencies</artifactId>
73+
<version>1.0.0-SNAPSHOT</version>
74+
<type>pom</type>
75+
<scope>import</scope>
76+
</dependency>
77+
</dependencies>
4278
</dependencyManagement>
4379
```
4480

45-
or Gradle:
81+
Gradle users can also use the Spring gRPC Dependencies by leveraging Gradle (5.0+) native support for declaring dependency constraints using a Maven BOM.
82+
This is implemented by adding a 'platform' dependency handler method to the dependencies section of your Gradle build script.
83+
As shown in the snippet below this can then be followed by version-less declarations of the Starter Dependencies for the one or more spring-grpc modules you wish to use, e.g. spring-grpc-openai.
4684

47-
```groovy
48-
dependencyManagement {
49-
imports {
50-
mavenBom 'org.springframework.grpc:spring-grpc-dependencies:0.1.0-SNAPSHOT'
51-
}
85+
```gradle
86+
dependencies {
87+
implementation platform("org.springframework.ai:spring-grpc-dependencies:1.0.0-SNAPSHOT")
88+
// Replace the following with the starter dependencies of specific modules you wish to use
89+
implementation 'org.springframework.ai:spring-grpc-openai'
5290
}
5391
```
5492

55-
Then you can omit the version from the dependencies.
56-
5793
You need a Protobuf file that defines your service and messages, and you will need to configure your build tools to compile it into Java sources. This is a standard part of gRPC development (i.e. nothing to do with Spring). We now come to the Spring gRPC features.
5894

59-
### gPRC Server
95+
## gPRC Server
6096

6197
Create a `@Bean` of type `BindableService`. For example:
6298

@@ -69,7 +105,7 @@ public class GrpcServerService extends SimpleGrpc.SimpleImplBase {
69105

70106
(`BindableService` is the interface that gRPC uses to bind services to the server and `SimpleImplBase` was created for you from your Protobuf file.)
71107

72-
Then, you can just run your application and the gRPC server will be started on the default port (9090). Here's a simple example (standard Spring Boot application):
108+
Then, you can just run your application and the gRPC server will be started on the default port (9090). Heres a simple example (standard Spring Boot application):
73109

74110
```java
75111
@SpringBootApplication
@@ -82,9 +118,9 @@ public class GrpcServerApplication {
82118

83119
Run it from your IDE, or on the command line with `mvn spring-boot:run` or `gradle bootRun`.
84120

85-
### gRPC Client
121+
## gRPC Client
86122

87-
To create a simple gRPC client, you can use the Spring Boot starter (see above - it's the same as for the server). Then you can inject a bean of type `GrpcChannelFactory` and use it to create a gRPC channel. The most common usage of a channel is to create a client that binds to a service, such as the one above. The Protobuf-generated sources in your project will contain the stub classes, and they just need to be bound to a channel. For example, to bind to the `SimpleGrpc` service on a local server:
123+
To create a simple gRPC client, you can use the Spring Boot starter (see above - its the same as for the server). Then you can inject a bean of type `GrpcChannelFactory` and use it to create a gRPC channel. The most common usage of a channel is to create a client that binds to a service, such as the one above. The Protobuf-generated sources in your project will contain the stub classes, and they just need to be bound to a channel. For example, to bind to the `SimpleGrpc` service on a local server:
88124

89125
```java
90126
@Bean
@@ -111,24 +147,3 @@ spring.grpc.client.channels.local.address=0.0.0.0:9090
111147
```
112148

113149
There is a default named channel (named "default") that you can configure in the same way, and then it will be used by default if there is no channel with the name specified in the channel creation.
114-
115-
## Building
116-
117-
To build with unit tests
118-
119-
```shell
120-
./mvnw clean package
121-
```
122-
123-
```
124-
To build the docs
125-
```shell
126-
./mvnw -pl spring-grpc-docs antora
127-
```
128-
129-
The docs are then in the directory `spring-grpc-docs/target/antora/site/index.html`
130-
131-
To reformat using the [java-format plugin](https://github.com/spring-io/spring-javaformat)
132-
```shell
133-
./mvnw spring-javaformat:apply
134-
```

spring-grpc-docs/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Spring gRPC Docs
22

3+
## README
4+
5+
The top level README is generated from sources in this module.
6+
7+
```
8+
$ cd spring-grpc-docs
9+
$ asciidoctor-reducer src/main/antora/modules/ROOT/pages/README.adoc | downdoc - > ../README.md
10+
```
11+
12+
where [`asciidoctor-reducer`](https://github.com/asciidoctor/asciidoctor-reducer) is a gem (so probably in `~/.gem/ruby/<version>/bin/asciidoctor-reducer`) and [`downdoc`](https://github.com/opendevise/downdoc) is an `npm` module, so `./node_modules/.bin/downdoc`.
13+
314
## Configuration Properties
415
The Spring gRPC configuration properties are automatically documented as follows:
516

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
////
2+
DO NOT EDIT THIS FILE. IT WAS GENERATED.
3+
Manual changes to this file will be lost when it is generated again.
4+
Edit the files in the spring-grpc-docs/src/main/antora/ directory instead.
5+
////
6+
:doctype: book
7+
8+
= Spring gRPC
9+
image::https://github.com/spring-projects-experimental/spring-grpc/actions/workflows/deploy.yml/badge.svg["Build Status", link="https://github.com/spring-projects/spring-grpc/actions/workflows/deploy.yml"]
10+
11+
Welcome to the Spring gRPC project!
12+
13+
The Spring gRPC project provides a Spring-friendly API and abstractions for developing gRPC applications. There is a core library that makes it easy to work with gRPC and dependency injection, and a Spring Boot starter that makes it easy to get started with gRPC in a Spring Boot application (with autoconfiguration and configuration properties, for instance).
14+
15+
For further information go to our [Spring gRPC reference documentation](https://docs.spring.io/spring-grpc/reference/).
16+
17+
include::getting-started.adoc[]

spring-grpc-docs/src/main/antora/modules/ROOT/pages/contribution-guidelines.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ while following a common implementation and documentation pattern.
3737
If you have a question, check https://stackoverflow.com/tags/spring[StackOverflow] using the https://stackoverflow.com/tags/grpc-java[grpc-java] tag.
3838
Find an existing discussion or start a new one if necessary.
3939

40-
If you suspect an issue, perform a search in the GitHub tracker of the R2DBC project, using a few different keywords.
40+
If you suspect an issue, perform a search in the GitHub tracker of the Spring gRPC project, using a few different keywords.
4141
When you find related issues and discussions, prior or current, it helps you to learn and it helps us to make a decision.
4242

4343
=== Create a Ticket

spring-grpc-docs/src/main/antora/modules/ROOT/pages/getting-started.adoc

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[[getting-started]]
22
= Getting Started
33

4-
This section offers jumping off points for how to get started using Spring gRPC.
4+
This section offers jumping off points for how to get started using Spring gRPC. There is a simple sample project in the `samples` directory (e.g. [`grpc-server`](https://github.com/spring-projects-experimental/spring-grpc/tree/main/samples/grpc-server)). You can run it with `mvn spring-boot:run` or `gradle bootRun`. You will see the following code in that sample.
5+
56

67
You should follow the steps in each of the following section according to your needs.
78

@@ -14,7 +15,7 @@ If you prefer to add the dependency snippets by hand, follow the directions in t
1415

1516
To use the Milestone and Snapshot version, you need to add references to the Spring Milestone and/or Snapshot repositories in your build file.
1617

17-
For Maven, add the following repository definitions as needed:
18+
For Maven, add the following repository definitions as needed (if you are using snapshots or milestones):
1819

1920
[source,xml]
2021
----
@@ -53,12 +54,12 @@ repositories {
5354
[[dependency-management]]
5455
== Dependency Management
5556

56-
The Spring gRPC Bill of Materials (BOM) declares the recommended versions of all the dependencies used by a given release of Spring gRPC.
57-
Using the BOM from your application’s build script avoids the need for you to specify and maintain the dependency versions yourself.
58-
Instead, the version of the BOM you’re using determines the utilized dependency versions.
57+
The Spring gRPC Dependencies declares the recommended versions of all the dependencies used by a given release of Spring gRPC.
58+
Using the dependencies from your application’s build script avoids the need for you to specify and maintain the dependency versions yourself.
59+
Instead, the version you’re using determines the utilized dependency versions.
5960
It also ensures that you’re using supported and tested versions of the dependencies by default, unless you choose to override them.
6061

61-
If you’re a Maven user, you can use the BOM by adding the following to your pom.xml file -
62+
If you’re a Maven user, you can use the dependencies by adding the following to your pom.xml file -
6263

6364
[source,xml]
6465
----
@@ -75,7 +76,7 @@ If you’re a Maven user, you can use the BOM by adding the following to your po
7576
</dependencyManagement>
7677
----
7778

78-
Gradle users can also use the Spring gRPC BOM by leveraging Gradle (5.0+) native support for declaring dependency constraints using a Maven BOM.
79+
Gradle users can also use the Spring gRPC Dependencies by leveraging Gradle (5.0+) native support for declaring dependency constraints using a Maven BOM.
7980
This is implemented by adding a 'platform' dependency handler method to the dependencies section of your Gradle build script.
8081
As shown in the snippet below this can then be followed by version-less declarations of the Starter Dependencies for the one or more spring-grpc modules you wish to use, e.g. spring-grpc-openai.
8182

@@ -87,3 +88,66 @@ dependencies {
8788
implementation 'org.springframework.ai:spring-grpc-openai'
8889
}
8990
----
91+
92+
You need a Protobuf file that defines your service and messages, and you will need to configure your build tools to compile it into Java sources. This is a standard part of gRPC development (i.e. nothing to do with Spring). We now come to the Spring gRPC features.
93+
94+
== gPRC Server
95+
96+
Create a `@Bean` of type `BindableService`. For example:
97+
98+
[source,java]
99+
----
100+
@Service
101+
public class GrpcServerService extends SimpleGrpc.SimpleImplBase {
102+
...
103+
}
104+
----
105+
106+
(`BindableService` is the interface that gRPC uses to bind services to the server and `SimpleImplBase` was created for you from your Protobuf file.)
107+
108+
Then, you can just run your application and the gRPC server will be started on the default port (9090). Here's a simple example (standard Spring Boot application):
109+
110+
[source,java]
111+
----
112+
@SpringBootApplication
113+
public class GrpcServerApplication {
114+
public static void main(String[] args) {
115+
SpringApplication.run(GrpcServerApplication.class, args);
116+
}
117+
}
118+
----
119+
120+
Run it from your IDE, or on the command line with `mvn spring-boot:run` or `gradle bootRun`.
121+
122+
== gRPC Client
123+
124+
To create a simple gRPC client, you can use the Spring Boot starter (see above - it's the same as for the server). Then you can inject a bean of type `GrpcChannelFactory` and use it to create a gRPC channel. The most common usage of a channel is to create a client that binds to a service, such as the one above. The Protobuf-generated sources in your project will contain the stub classes, and they just need to be bound to a channel. For example, to bind to the `SimpleGrpc` service on a local server:
125+
126+
[source,java]
127+
----
128+
@Bean
129+
SimpleGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels) {
130+
return SimpleGrpc.newBlockingStub(channels.createChannel("0.0.0.0:9090").build());
131+
}
132+
----
133+
134+
Then you can inject the stub and use it in your application.
135+
136+
The default `GrpcChannelFactory` implementation can also create a "named" channel, which you can then use to extract the configuration to connect to the server. For example:
137+
138+
[source,java]
139+
----
140+
@Bean
141+
SimpleGrpc.SimpleBlockingStub stub(GrpcChannelFactory channels) {
142+
return SimpleGrpc.newBlockingStub(channels.createChannel("local").build());
143+
}
144+
----
145+
146+
then in `application.properties`:
147+
148+
[source,properties]
149+
----
150+
spring.grpc.client.channels.local.address=0.0.0.0:9090
151+
----
152+
153+
There is a default named channel (named "default") that you can configure in the same way, and then it will be used by default if there is no channel with the name specified in the channel creation.

0 commit comments

Comments
 (0)