Client
This commit is contained in:
@@ -7,5 +7,24 @@ import io.grpc.*;
|
||||
|
||||
public class EchoClient {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
ManagedChannel channel = ManagedChannelBuilder
|
||||
.forAddress("localhost", 8080) //serveur localhost, port 8080
|
||||
.usePlaintext() // on demande a ne pas utiliser tls
|
||||
.build(); // pattern builder
|
||||
|
||||
//On utilise un stub bloquant pour faire la requête (on bloque jusqu'à réponse)
|
||||
EchoServiceGrpc.EchoServiceBlockingStub stub = EchoServiceGrpc.newBlockingStub(channel);
|
||||
//On construit la requête :
|
||||
MessageSent request = MessageSent.newBuilder().setMessage("ilililili").build();
|
||||
|
||||
// On appelle le serveur :
|
||||
MessageReceive response = stub.echo(request);
|
||||
|
||||
// On affiche le résultat
|
||||
System.out.println("Reçu : " + response.getMessage());
|
||||
channel.shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
package fr.istic.grpc.echo;
|
||||
|
||||
import fr.istic.grpc.echo.Echo.MessageReceive;
|
||||
import fr.istic.grpc.echo.Echo.MessageSent;
|
||||
import fr.istic.grpc.todo.*;
|
||||
import io.grpc.*;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public class EchoServeur {
|
||||
|
||||
public void echo(MessageSent min, StreamObserver<MessageReceive> responseObserver) {
|
||||
MessageReceive reply = MessageReceive.newBuilder().setMessage(min.getMessage().toUpperCase()).build();
|
||||
responseObserver.onNext(reply);
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,13 @@ package echo;
|
||||
option java_package = "fr.istic.grpc.echo";
|
||||
|
||||
service EchoService {
|
||||
|
||||
rpc Echo(MessageSent) returns (MessageReceive) {}
|
||||
}
|
||||
|
||||
message MessageSent{
|
||||
string message = 1;
|
||||
}
|
||||
|
||||
message MessageReceive{
|
||||
string message = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user