This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const html = (requestTime) => `<!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <!-- Required meta tags --> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
| <title>Running Successfull</title> | |
| </head> | |
| <script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var buttonMachine = Machine({ | |
| id: 'policy', | |
| initial: 'activated', | |
| states: { | |
| activated: { | |
| on: { | |
| update: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void chat() throws InterruptedException { | |
| DemoServiceGrpc.DemoServiceStub stub = DemoServiceGrpc.newStub(channel); | |
| StreamObserver<ChatRequest> request = stub.chat(new StreamObserver<ChatResponse>() { | |
| @Override | |
| public void onNext(ChatResponse chatResponse) { | |
| // called everytime server replies | |
| System.out.println(chatResponse.getReply()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public StreamObserver<ChatRequest> chat(StreamObserver<ChatResponse> responseObserver) { | |
| return new StreamObserver<ChatRequest>() { | |
| @Override | |
| public void onNext(ChatRequest chatRequest) { | |
| // extract the message | |
| String message = chatRequest.getMessage(); | |
| // create the response | |
| ChatResponse response = ChatResponse.newBuilder() | |
| .setReply("server says thanks for sending: " + message) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| message ChatRequest { | |
| string message = 1; | |
| } | |
| message ChatResponse { | |
| string reply = 1; | |
| } | |
| service DemoService { | |
| rpc Sum(SumRequest) returns (SumResponse); | |
| rpc Chat(stream ChatRequest) returns (stream ChatResponse); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // step 1 - creating the channel | |
| ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 3000) | |
| .usePlaintext() | |
| .build(); | |
| // step 2 - creating the stub | |
| DemoServiceGrpc.DemoServiceBlockingStub stub = DemoServiceGrpc.newBlockingStub(channel); | |
| // request | |
| SumRequest request = SumRequest.newBuilder() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Application { | |
| public static void main(String[] args) throws IOException, InterruptedException { | |
| Server server = ServerBuilder.forPort(3000) | |
| .addService(new DemoServiceImpl()) | |
| .build(); | |
| server.start(); | |
| // boring boilerplate here | |
| Runtime.getRuntime().addShutdownHook(new Thread(() -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.grpc.stub.StreamObserver; | |
| public class DemoServiceImpl extends DemoServiceGrpc.DemoServiceImplBase { | |
| @Override | |
| public void sum(SumRequest request, StreamObserver<SumResponse> responseObserver) { | |
| int num1 = request.getNum1(); | |
| int num2 = request.getNum2(); | |
| int result = num1 + num2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DemoServiceImpl extends DemoServiceGrpc.DemoServiceImplBase { | |
| @Override | |
| public void sum (SumRequest request, StreamObserver responseObserver) { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| syntax = 'proto3' ; | |
| message SumRequest { | |
| int32 num1 = 1 ; | |
| int32 num2 = 2 ; | |
| } | |
| message SumResponse { | |
| int32 sum = 1 ; | |
| } | |
| service DemoService { | |
| rpc Sum ( SumRequest ) returns ( SumResponse ) ; |
NewerOlder