Skip to content

Commit

Permalink
Use the vertx protoc plugin2 instead of the legacy one
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jul 25, 2024
1 parent bb38d76 commit fb02693
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 86 deletions.
4 changes: 2 additions & 2 deletions grpc-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
<protocPlugin>
<id>vertx-grpc-protoc-plugin</id>
<groupId>io.vertx</groupId>
<artifactId>vertx-grpc-protoc-plugin</artifactId>
<artifactId>vertx-grpc-protoc-plugin2</artifactId>
<version>${project.version}</version>
<mainClass>io.vertx.grpc.protoc.plugin.VertxGrpcGenerator</mainClass>
<mainClass>io.vertx.grpc.plugin.VertxGrpcGenerator</mainClass>
</protocPlugin>
</protocPlugins>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxConsumerServiceGrpc;
import io.vertx.example.grpc.VertxConsumerServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

import java.nio.charset.StandardCharsets;

Expand All @@ -24,10 +23,9 @@ public void start() {

// Create the channel
GrpcClient client = GrpcClient.client(vertx);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Get a stub to use for interacting with the remote service
VertxConsumerServiceGrpc.ConsumerServiceVertxStub stub = VertxConsumerServiceGrpc.newVertxStub(channel);
VertxConsumerServiceGrpcClient stub = new VertxConsumerServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Make a request
Messages.StreamingOutputCallRequest request = Messages
Expand All @@ -36,10 +34,13 @@ public void start() {
.build();

// Call the remote service
stub.streamingOutputCall(request).handler(response -> {
System.out.println(new String(response.getPayload().toByteArray(), StandardCharsets.UTF_8));
}).endHandler(v -> {
System.out.println("Response has ended.");
});
stub.streamingOutputCall(request)
.onSuccess(response -> {
response.handler(msg -> {
System.out.println(new String(msg.getPayload().toByteArray(), StandardCharsets.UTF_8));
}).endHandler(v -> {
System.out.println("Response has ended.");
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import io.vertx.core.streams.WriteStream;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.Messages.PayloadType;
import io.vertx.example.grpc.VertxConsumerServiceGrpc;
import io.vertx.example.grpc.VertxConsumerServiceGrpcServer;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;

import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -26,7 +25,7 @@ public static void main(String[] args) {
public void start() {

// The rpc service
VertxConsumerServiceGrpc.ConsumerServiceVertxImplBase service = new VertxConsumerServiceGrpc.ConsumerServiceVertxImplBase() {
VertxConsumerServiceGrpcServer.ConsumerServiceApi service = new VertxConsumerServiceGrpcServer.ConsumerServiceApi() {
@Override
public void streamingOutputCall(Messages.StreamingOutputCallRequest request, WriteStream<Messages.StreamingOutputCallResponse> response) {
final AtomicInteger counter = new AtomicInteger();
Expand All @@ -43,9 +42,9 @@ public void streamingOutputCall(Messages.StreamingOutputCallRequest request, Wri

// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);

// Bind the service
service.bind_streamingOutputCall(rpcServer);

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxConversationalServiceGrpc;
import io.vertx.example.grpc.VertxConversationalServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

/*
* @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
Expand All @@ -22,10 +21,9 @@ public void start() {

// Create the channel
GrpcClient client = GrpcClient.client(vertx);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Get a stub to use for interacting with the remote service
VertxConversationalServiceGrpc.ConversationalServiceVertxStub stub = VertxConversationalServiceGrpc.newVertxStub(channel);
VertxConversationalServiceGrpcClient stub = new VertxConversationalServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Call the remote service
stub.fullDuplexCall(writeStream -> {
Expand All @@ -34,8 +32,10 @@ public void start() {
vertx.setTimer(500L, t -> {
writeStream.write(Messages.StreamingOutputCallRequest.newBuilder().build());
});
}).handler(req -> {
System.out.println("Client: received response");
}).onSuccess(resp -> {
resp.handler(msg -> {
System.out.println("Client: received response");
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.vertx.core.streams.ReadStream;
import io.vertx.core.streams.WriteStream;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxConversationalServiceGrpc;
import io.vertx.example.grpc.VertxConversationalServiceGrpcServer;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;

Expand All @@ -23,7 +23,7 @@ public static void main(String[] args) {
public void start() {

// The rpc service
VertxConversationalServiceGrpc.ConversationalServiceVertxImplBase service = new VertxConversationalServiceGrpc.ConversationalServiceVertxImplBase() {
VertxConversationalServiceGrpcServer.ConversationalServiceApi service = new VertxConversationalServiceGrpcServer.ConversationalServiceApi() {
@Override
public void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> request, WriteStream<Messages.StreamingOutputCallResponse> response) {
request
Expand All @@ -38,9 +38,9 @@ public void fullDuplexCall(ReadStream<Messages.StreamingOutputCallRequest> reque

// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);

// Bind the service
service.bind_fullDuplexCall(rpcServer);

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.EmptyProtos;
import io.vertx.example.grpc.VertxEmptyPingPongServiceGrpc;
import io.vertx.example.grpc.VertxEmptyPingPongServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

/*
* @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
Expand All @@ -22,10 +21,9 @@ public void start() {

// Create the channel
GrpcClient client = GrpcClient.client(vertx);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Get a stub to use for interacting with the remote service
VertxEmptyPingPongServiceGrpc.EmptyPingPongServiceVertxStub stub = VertxEmptyPingPongServiceGrpc.newVertxStub(channel);
VertxEmptyPingPongServiceGrpcClient stub = new VertxEmptyPingPongServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Make a request
EmptyProtos.Empty request = EmptyProtos.Empty.newBuilder().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.vertx.example.grpc.helloworld;

import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpc;
import io.grpc.examples.helloworld.VertxGreeterGrpcClient;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
Expand All @@ -20,8 +19,7 @@ public static void main(String[] args) {
@Override
public void start() {
GrpcClient client = GrpcClient.client(vertx);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));
VertxGreeterGrpc.GreeterVertxStub stub = VertxGreeterGrpc.newVertxStub(channel);
VertxGreeterGrpcClient stub = new VertxGreeterGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));
HelloRequest request = HelloRequest.newBuilder().setName("Julien").build();
stub.sayHello(request).onComplete(asyncResponse -> {
if (asyncResponse.succeeded()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import io.grpc.examples.helloworld.HelloReply;
import io.grpc.examples.helloworld.HelloRequest;
import io.grpc.examples.helloworld.VertxGreeterGrpc;
import io.grpc.examples.helloworld.VertxGreeterGrpcServer;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Launcher;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;

/**
* @author <a href="mailto:julien@julienviet.com">Julien Viet</a>
Expand All @@ -20,7 +19,7 @@ public static void main(String[] args) {

@Override
public void start() {
VertxGreeterGrpc.GreeterVertxImplBase service = new VertxGreeterGrpc.GreeterVertxImplBase() {
VertxGreeterGrpcServer.GreeterApi service = new VertxGreeterGrpcServer.GreeterApi() {
@Override
public Future<HelloReply> sayHello(HelloRequest request) {
System.out.println("Hello " + request.getName());
Expand All @@ -30,9 +29,9 @@ public Future<HelloReply> sayHello(HelloRequest request) {

// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);

// Bind the service
service.bind_sayHello(rpcServer);

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxPingPongServiceGrpc;
import io.vertx.example.grpc.VertxPingPongServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

/*
* @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
Expand All @@ -22,10 +21,9 @@ public void start() {

// Create the channel
GrpcClient client = GrpcClient.client(vertx);
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Get a stub to use for interacting with the remote service
VertxPingPongServiceGrpc.PingPongServiceVertxStub stub = VertxPingPongServiceGrpc.newVertxStub(channel);
VertxPingPongServiceGrpcClient stub = new VertxPingPongServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Make a request
Messages.SimpleRequest request = Messages.SimpleRequest.newBuilder().setFillUsername(true).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.vertx.example.grpc.pingpong;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Launcher;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxPingPongServiceGrpc;
import io.vertx.example.grpc.PingPongServiceGrpc;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;

/*
* @author <a href="mailto:plopes@redhat.com">Paulo Lopes</a>
Expand All @@ -20,19 +18,17 @@ public static void main(String[] args) {
@Override
public void start() {

// The rpc service
VertxPingPongServiceGrpc.PingPongServiceVertxImplBase service = new VertxPingPongServiceGrpc.PingPongServiceVertxImplBase() {
@Override
public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request) {
return Future.succeededFuture(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
}
};

// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);

//
rpcServer.callHandler(PingPongServiceGrpc.getUnaryCallMethod(), request -> {
request
.last()
.onSuccess(msg -> {
request.response().end(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
});
});

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import io.vertx.core.Future;
import io.vertx.core.Launcher;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.PingPongServiceGrpc;
import io.vertx.example.grpc.VertxPingPongServiceGrpc;
import io.vertx.example.grpc.VertxPingPongServiceGrpcServer;
import io.vertx.grpc.server.GrpcServer;

/*
Expand All @@ -21,7 +20,7 @@ public static void main(String[] args) {
public void start() {

// The rpc service
VertxPingPongServiceGrpc.PingPongServiceVertxImplBase service = new VertxPingPongServiceGrpc.PingPongServiceVertxImplBase() {
VertxPingPongServiceGrpcServer.PingPongServiceApi service = new VertxPingPongServiceGrpcServer.PingPongServiceApi() {
@Override
public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request) {
return Future.succeededFuture(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
Expand All @@ -31,14 +30,8 @@ public Future<Messages.SimpleResponse> unaryCall(Messages.SimpleRequest request)
// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);

// The rpc service
rpcServer.callHandler(PingPongServiceGrpc.getUnaryCallMethod(), request -> {
request
.last()
.onSuccess(msg -> {
request.response().end(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
});
});
// Bind the service
service.bind_unaryCall(rpcServer);

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.vertx.core.Launcher;
import io.vertx.core.net.SocketAddress;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxProducerServiceGrpc;
import io.vertx.example.grpc.VertxProducerServiceGrpcClient;
import io.vertx.grpc.client.GrpcClient;
import io.vertx.grpc.client.GrpcClientChannel;

Expand All @@ -25,7 +25,7 @@ public void start() {
GrpcClientChannel channel = new GrpcClientChannel(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Get a stub to use for interacting with the remote service
VertxProducerServiceGrpc.ProducerServiceVertxStub stub = VertxProducerServiceGrpc.newVertxStub(channel);
VertxProducerServiceGrpcClient stub = new VertxProducerServiceGrpcClient(client, SocketAddress.inetSocketAddress(8080, "localhost"));

// Call the remote service
stub.streamingInputCall(writeStream -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.vertx.core.Promise;
import io.vertx.core.streams.ReadStream;
import io.vertx.example.grpc.Messages;
import io.vertx.example.grpc.VertxProducerServiceGrpc;
import io.vertx.example.grpc.VertxProducerServiceGrpcServer;
import io.vertx.grpc.server.GrpcServer;
import io.vertx.grpc.server.GrpcServiceBridge;

Expand All @@ -23,7 +23,7 @@ public static void main(String[] args) {
public void start() {

// The rpc service
VertxProducerServiceGrpc.ProducerServiceVertxImplBase service = new VertxProducerServiceGrpc.ProducerServiceVertxImplBase() {
VertxProducerServiceGrpcServer.ProducerServiceApi service = new VertxProducerServiceGrpcServer.ProducerServiceApi() {
@Override
public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream<Messages.StreamingInputCallRequest> request) {
Promise<Messages.StreamingInputCallResponse> promise = Promise.promise();
Expand All @@ -39,9 +39,9 @@ public Future<Messages.StreamingInputCallResponse> streamingInputCall(ReadStream

// Create the server
GrpcServer rpcServer = GrpcServer.server(vertx);
GrpcServiceBridge
.bridge(service)
.bind(rpcServer);

// Bind the service
service.bind_streamingInputCall(rpcServer);

// start the server
vertx.createHttpServer().requestHandler(rpcServer).listen(8080)
Expand Down
Loading

0 comments on commit fb02693

Please sign in to comment.