use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
ProducerServiceGrpc.ProducerServiceVertxImplBase service = new ProducerServiceGrpc.ProducerServiceVertxImplBase() {
@Override
public void streamingInputCall(GrpcReadStream<Messages.StreamingInputCallRequest> request, Future<Messages.StreamingInputCallResponse> future) {
request.handler(payload -> {
System.out.println(payload.getPayload().getType().getNumber());
}).endHandler(v -> {
System.out.println("Request has ended.");
future.complete(Messages.StreamingInputCallResponse.newBuilder().build());
});
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
URL featureFile = Util.getDefaultFeaturesFile();
features = Util.parseFeatures(featureFile);
VertxServer server = VertxServerBuilder.forAddress(vertx, "localhost", 8080).addService(new RouteGuideGrpc.RouteGuideVertxImplBase() {
@Override
public void getFeature(Point request, Future<Feature> response) {
response.complete(checkFeature(request));
}
@Override
public void listFeatures(Rectangle request, GrpcWriteStream<Feature> response) {
int left = Math.min(request.getLo().getLongitude(), request.getHi().getLongitude());
int right = Math.max(request.getLo().getLongitude(), request.getHi().getLongitude());
int top = Math.max(request.getLo().getLatitude(), request.getHi().getLatitude());
int bottom = Math.min(request.getLo().getLatitude(), request.getHi().getLatitude());
for (Feature feature : features) {
if (!Util.exists(feature)) {
continue;
}
int lat = feature.getLocation().getLatitude();
int lon = feature.getLocation().getLongitude();
if (lon >= left && lon <= right && lat >= bottom && lat <= top) {
response.write(feature);
}
}
response.end();
}
@Override
public void recordRoute(GrpcReadStream<Point> request, Future<RouteSummary> response) {
request.exceptionHandler(err -> {
System.out.println("recordRoute cancelled");
});
RouteRecorder recorder = new RouteRecorder();
request.handler(recorder::append);
request.endHandler(v -> {
response.complete(recorder.build());
});
}
@Override
public void routeChat(GrpcBidiExchange<RouteNote, RouteNote> exchange) {
exchange.handler(note -> {
List<RouteNote> notes = getOrCreateNotes(note.getLocation());
// Respond with all previous notes at this location.
for (RouteNote prevNote : notes.toArray(new RouteNote[0])) {
exchange.write(prevNote);
}
// Now add the new note to the list
notes.add(note);
});
exchange.exceptionHandler(err -> {
System.out.println("routeChat cancelled");
});
exchange.endHandler(v -> exchange.end());
}
}).build();
server.start(ar -> {
if (ar.succeeded()) {
System.out.println("gRPC service started");
} else {
System.out.println("Could not start server " + ar.cause().getMessage());
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
EmptyPingPongServiceGrpc.EmptyPingPongServiceVertxImplBase service = new EmptyPingPongServiceGrpc.EmptyPingPongServiceVertxImplBase() {
@Override
public void emptyCall(EmptyProtos.Empty request, Future<EmptyProtos.Empty> future) {
future.complete(EmptyProtos.Empty.newBuilder().build());
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-examples by vert-x3.
the class Server method start.
@Override
public void start() throws Exception {
// The rcp service
PingPongServiceGrpc.PingPongServiceVertxImplBase service = new PingPongServiceGrpc.PingPongServiceVertxImplBase() {
@Override
public void unaryCall(Messages.SimpleRequest request, Future<Messages.SimpleResponse> future) {
future.complete(Messages.SimpleResponse.newBuilder().setUsername("Paulo").build());
}
};
// Create the server
VertxServer rpcServer = VertxServerBuilder.forPort(vertx, 8080).addService(service).build();
// start the server
rpcServer.start(ar -> {
if (ar.failed()) {
ar.cause().printStackTrace();
}
});
}
use of io.vertx.grpc.VertxServer in project vertx-zero by silentbalanceyh.
the class ZeroRpcAgent method start.
@Override
public void start() {
/**
* 1. Iterate all the configuration *
*/
Fn.itMap(ZeroAtomic.RPC_OPTS, (port, config) -> {
/**
* 2.Rcp server builder initialized *
*/
final VertxServerBuilder builder = VertxServerBuilder.forAddress(this.vertx, config.getHost(), config.getPort());
/**
* 3.Service added.
*/
{
// UnityService add ( Envelop )
final Tunnel tunnel = Instance.singleton(UnityTunnel.class);
builder.addService(tunnel.init(this.vertx));
}
/**
* 4.Server added.
*/
final VertxServer server = builder.build();
server.start(handler -> this.registryServer(handler, config));
});
}
Aggregations