Sign inSign up

getjv/go-grpc-server

By getjv

Updated over 1 year ago

Basic grpc "Hello world like" services, unary and stream services good for learning purposes.

Image
Networking
API management
Developer tools
0

224

getjv/go-grpc-server repository overview

This is a GRPC server with basic features to support my laboratories, written articles, and videos it provides a sample of unary call, client streaming, server streaming and bidirectional streaming. All the samples are "Hello world like" but once you have the project structure is possible to extend it to any purpose.

visit my portfolio to find more about many topics.

the image src code is available in my github


How to use the image:

docker run --rm --name grpc -p 50051:50051 getjv/go-grpc-server

Exploring server calls with grpcURL

gRPCurl is a super handy tool, and the main commands are:

  • grpcurl -plaintext [::]:50051 list – lists the available services.
  • grpcurl -plaintext [::]:50051 describe <ServiceName> – provides more information about the available service.
  • grpcurl -plaintext -d '<JSON-Payload>' [::]:50051 <ServiceName.MethodName> – makes a direct call to a method with a payload.

Call samples:

Hello sample: it's a unary call with single request single response.

grpcurl -plaintext -d '{"name": "jhonatan"}' [::]:50051 helloworld.Greeter.SayHello

Server Streaming sample: it's a server streaming sample with 1 request and 10 messages from server

grpcurl -d '{"name": "Cliente"}' -plaintext localhost:50051 helloworld.Greeter/StreamGreetings

Client Streaming sample: it's a client streaming sample with 10 client requests and 1 message from server Here the steps are a bit different:

  1. Open the channel with:
grpcurl -plaintext -d @ localhost:50051 helloworld.Greeter/EchoGreetings
  1. the terminal will wait the input give the objects bellow and press enter:
{"name": "Alice"}
{"name": "Bob"}
{"name": "Charlie"}
  1. Now press CTRL+D to notify all was sent. Server will send you the final confirmation.

Bi-directional streaming: this is the most advanced sample an open channel to both sides keeping interacting to test execute:

  1. Open the channel with:
grpcurl -plaintext -d @ localhost:50051 helloworld.Greeter/OpenGreetings
  1. the terminal will wait the input give the objects bellow and press enter:
{"name": "Alice"}
  1. After each enter Server will send you a confirmation.
  2. Now press CTRL+D to notify you are done.

Tag summary

Content type

Image

Digest

sha256:609980869

Size

10.7 MB

Last updated

over 1 year ago

docker pull getjv/go-grpc-server