1
1
package io .vertx .example .grpc .consumer ;
2
2
3
+ import com .google .protobuf .ByteString ;
3
4
import io .vertx .core .AbstractVerticle ;
4
- import io .vertx .example .grpc .*;
5
+ import io .vertx .example .grpc .ConsumerServiceGrpc ;
6
+ import io .vertx .example .grpc .Messages ;
7
+ import io .vertx .example .grpc .Messages .PayloadType ;
5
8
import io .vertx .example .util .Runner ;
6
9
import io .vertx .grpc .GrpcWriteStream ;
7
10
import io .vertx .grpc .VertxServer ;
8
11
import io .vertx .grpc .VertxServerBuilder ;
9
-
12
+ import java . nio . charset . Charset ;
10
13
import java .util .concurrent .atomic .AtomicInteger ;
11
14
12
15
/*
@@ -23,15 +26,24 @@ public static void main(String[] args) {
23
26
public void start () throws Exception {
24
27
25
28
// The rcp service
26
- ConsumerServiceGrpc .ConsumerServiceVertxImplBase service = new ConsumerServiceGrpc .ConsumerServiceVertxImplBase () {
27
- @ Override
28
- public void streamingOutputCall (Messages .StreamingOutputCallRequest request , GrpcWriteStream <Messages .StreamingOutputCallResponse > response ) {
29
- final AtomicInteger counter = new AtomicInteger ();
30
- vertx .setPeriodic (1000L , t -> {
31
- response .write (Messages .StreamingOutputCallResponse .newBuilder ().setPayload (Messages .Payload .newBuilder ().setTypeValue (counter .incrementAndGet ())).build ());
32
- });
33
- }
34
- };
29
+ ConsumerServiceGrpc .ConsumerServiceVertxImplBase service =
30
+ new ConsumerServiceGrpc .ConsumerServiceVertxImplBase () {
31
+ @ Override
32
+ public void streamingOutputCall (
33
+ Messages .StreamingOutputCallRequest request ,
34
+ GrpcWriteStream <Messages .StreamingOutputCallResponse > response
35
+ ) {
36
+ final AtomicInteger counter = new AtomicInteger ();
37
+ vertx .setPeriodic (1000L , t -> {
38
+ response .write (Messages .StreamingOutputCallResponse .newBuilder ().setPayload (
39
+ Messages .Payload .newBuilder ()
40
+ .setTypeValue (PayloadType .COMPRESSABLE .getNumber ())
41
+ .setBody (ByteString .copyFrom (
42
+ String .valueOf (counter .incrementAndGet ()), Charset .forName ("UTF-8" )))
43
+ ).build ());
44
+ });
45
+ }
46
+ };
35
47
36
48
// Create the server
37
49
VertxServer rpcServer = VertxServerBuilder
0 commit comments