je put?
This commit is contained in:
@@ -9,11 +9,11 @@ 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
|
||||
.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);
|
||||
@@ -25,7 +25,6 @@ public class EchoClient {
|
||||
|
||||
// On affiche le résultat
|
||||
System.out.println("Reçu : " + response.getMessage());
|
||||
channel.shutdown();
|
||||
}
|
||||
|
||||
channel.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,29 @@
|
||||
package fr.istic.grpc.todo;
|
||||
|
||||
import fr.istic.grpc.echo.Echo;
|
||||
import fr.istic.grpc.echo.EchoServiceGrpc;
|
||||
import fr.istic.grpc.todo.Todo.*;
|
||||
import fr.istic.grpc.todo.TodoServiceGrpc.*;
|
||||
import io.grpc.*;
|
||||
|
||||
public class TodoClient {
|
||||
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)
|
||||
TodoServiceGrpc.TodoServiceBlockingStub stub = TodoServiceGrpc.newBlockingStub(channel);
|
||||
//On construit la requête :
|
||||
Echo.MessageSent request = Echo.MessageSent.newBuilder().setMessage("ilililili").build();
|
||||
|
||||
// On appelle le serveur :
|
||||
//Echo.MessageReceive response = stub.echo(request);
|
||||
|
||||
// On affiche le résultat
|
||||
//System.out.println("Reçu : " + response.getMessage());
|
||||
channel.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package fr.istic.grpc.todo;
|
||||
|
||||
import io.grpc.stub.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
@@ -12,13 +13,13 @@ public class TodoServiceImpl extends TodoServiceGrpc.TodoServiceImplBase {
|
||||
return taskId.incrementAndGet();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void createTask(Todo.CreateTaskRequest request, StreamObserver<Todo.TaskResponse> responseObserver) {
|
||||
// Créer une tâche en générant un identifiant
|
||||
Todo.TaskResponse tr = Todo.TaskResponse.newBuilder().setId(Integer.toString(generateUniqueTaskId()))
|
||||
.setDescription(request.getDescription()).build();
|
||||
responseObserver.onNext(tr);
|
||||
responseObserver.onCompleted();
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void listTasks(Todo.ListTasksRequest request, StreamObserver<Todo.ListTasksResponse> responseObserver) {
|
||||
// La réponse est une liste
|
||||
|
||||
@@ -5,7 +5,9 @@ option java_package = "fr.istic.grpc.todo";
|
||||
|
||||
// Le service TodoService définit les opérations disponibles pour gérer les tâches.
|
||||
service TodoService {
|
||||
// A COMPLETER !
|
||||
rpc Create(CreateTaskRequest) returns (TaskResponse){}
|
||||
rpc View(ListTasksRequest) returns (ListTasksResponse){}
|
||||
rpc Delete(DeleteTaskRequest) returns (TaskResponse){}
|
||||
}
|
||||
|
||||
// Message de requête pour créer une nouvelle tâche.
|
||||
|
||||
Reference in New Issue
Block a user