11= Spring boot starter for http://www.grpc.io/[gRPC framework.] https://bintray.com/lognet/maven/grpc-spring-boot-starter/_latestVersion[ image:https://api.bintray.com/packages/lognet/maven/grpc-spring-boot-starter/images/download.svg[Download]] image:https://travis-ci.org/LogNet/grpc-spring-boot-starter.svg?branch=master[Build Status,link=https://travis-ci.org/LogNet/grpc-spring-boot-starter] https://bintray.com/lognet/maven/grpc-spring-boot-starter?source=watch[ image:https://www.bintray.com/docs/images/bintray_badge_color.png[]]
2- :toc: left
3- :doctype: book
4- :toclevels: 4
5- :source-highlighter: prettify
6- :numbered:
7- :icons: font
2+ :toc:
83
94
105== Features
@@ -172,16 +167,18 @@ Below are the essential parts of configurations for both server and client proje
172167 }
173168----
174169
170+
175171* Configure gRPC server to register itself with Eureka.
176172
173+
177174[source,yaml]
178175.bootstrap.yaml
179176----
180177spring:
181178 application:
182179 name: my-service-name <1>
183180----
184- <1> Eureka's `ServiceId` by default is the spring application name, provide it before the service register itself with Eureka.
181+ <1> Eureka's `ServiceId` by default is the spring application name, provide it before the service registers itself with Eureka.
185182
186183[source,yaml]
187184.application.yaml
@@ -195,34 +192,36 @@ eureka:
195192 serviceUrl:
196193 defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ <3>
197194----
195+
198196<1> Specify the port number the gRPC is listening on.
199197<2> Register the eureka service port to be the same as `grpc.port` so client will know where to send the requests to.
200- <3> Specify the registry URL, so the service will register itself using this URL.
198+ <3> Specify the registry URL, so the service will register itself with.
199+
200+ d
201+ * Expose the gRPC service as part of Spring Boot Application.
201202
202- * Expose the gRPC service as part of Spring Boot Application.
203203
204204[source,java]
205205.EurekaGrpcServiceApp.java
206206----
207- @SpringBootApplication
208- @EnableEurekaClient
209- public class EurekaGrpcServiceApp {
207+ @SpringBootApplication
208+ @EnableEurekaClient
209+ public class EurekaGrpcServiceApp {
210210
211- @GRpcService
212- public static class GreeterService extends GreeterGrpc.GreeterImplBase {
213- @Override
214- public void sayHello(GreeterOuterClass.HelloRequest request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) {
215- ...
216- }
217- }
211+ @GRpcService
212+ public static class GreeterService extends GreeterGrpc.GreeterImplBase {
213+ @Override
214+ public void sayHello(GreeterOuterClass.HelloRequest request, StreamObserver<GreeterOuterClass.HelloReply> responseObserver) {
218215
219- public static void main(String[] args) {
220- SpringApplication.run(DemoApp.class,args);
221- }
216+ }
217+ }
222218
223- }
224- ----
219+ public static void main(String[] args) {
220+ SpringApplication.run(DemoApp.class,args);
221+ }
225222
223+ }
224+ ----
226225
227226=== gRPC Client Project
228227
@@ -248,42 +247,50 @@ eureka:
248247 service-url:
249248 defaultZone: http://${eureka.host:localhost}:${eureka.port:8761}/eureka/ <2>
250249----
251- <1> `false` if this project is not meant to act as a `service` to another client.
252- <2> Specify the registry URL, so this client will know where to lookup the required service.
253250
254- * Use `EurekaClient` to get the coordinates of grpc service instance from Eureka:
251+ <1> `false` if this project is not meant to act as a service to another client.
252+ <2> Specify the registry URL, so this client will know where to look up the required service.
253+
254+ * Use EurekaClient to get the coordinates of gRPC service instance from Eureka.
255255
256- [source,java]
257- .GreeterServiceConsumerApplication.java
258- ----
256+ [source,java]
257+ .GreeterServiceConsumerApplication.java
258+ ----
259259 @EnableEurekaClient
260260 @SpringBootApplication
261261 public class GreeterServiceConsumerApplication {
262- public static void main(String[] args) {
263- SpringApplication.run(GreeterServiceConsumerApplication.class, args);
264- }
262+ public static void main(String[] args) {
263+ SpringApplication.run(GreeterServiceConsumerApplication.class, args);
264+ }
265265 }
266- ----
267-
268- [source,java]
269- .GreeterServiceConsumer.java
270- ----
271- @EnableEurekaClient
272- @Component
273- public class GreeterServiceConsumer {
266+ ----
267+
268+
269+
270+ [source,java]
271+ .GreeterServiceConsumer.java
272+ ----
273+ @EnableEurekaClient
274+ @Component
275+ public class GreeterServiceConsumer {
274276 @Autowired
275277 private EurekaClient client;
276- public DeferredResult<String> foo(String name) {
277- final InstanceInfo instanceInfo = client.getNextServerFromEureka("my-service-name", false);
278+
279+ public void greet(String name) {
280+ final InstanceInfo instanceInfo = client.getNextServerFromEureka("my-service-name", false);<1>
278281 final ManagedChannel channel = ManagedChannelBuilder.forAddress(instanceInfo.getIPAddr(), instanceInfo.getPort())
279282 .usePlaintext(true)
280- .build();
281- final GreeterServiceGrpc.GreeterServiceFutureStub stub = GreeterServiceGrpc.newFutureStub(channel);
283+ .build(); <2>
284+ final GreeterServiceGrpc.GreeterServiceFutureStub stub = GreeterServiceGrpc.newFutureStub(channel); <3>
282285 stub.greet(name);
283286
284287 }
285- }
286- ----
288+ }
289+ ----
290+ <1> Get the information about the `my-service-name` instance.
291+ <2> Build `channel` accordingly.
292+ <3> Create stub using the `channel`.
293+
287294
288295
289296== License
0 commit comments