go-grpc

module
v0.0.0-...-e3d380c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2020 License: Apache-2.0

README

go-grpc

gRPC example in Golang

Services


Codebase

Prerequisites
  1. Compile protobufs
    protoc --proto_path=./proto/ --go_out=plugins=grpc:domain ./proto/*
    
Build
  1. Server (hello-service)

    go build -o grpc-server ./hello-service
    
  2. Client (greeting-service)

    go build -o grpc-client ./greeting-service
    
Run
  1. Start server (hello-service)

    GO111MODULE=on go run ./hello-service/main.go
    
  2. In another shell, start client (greeting-service)

    GO111MODULE=on go run ./greeting-service/main.go
    

Polyglot test

This repo can be used for a polyglot test together with java-grpc

Go client --> Java server
  1. Start server (hello-service)

    cd java-grpc/hello-service
    mvnw clean spring-boot:run
    
  2. In another shell, start client (greeting-service)

    GO111MODULE=on go run ./greeting-service/main.go
    
Java client --> Go server
  1. Start server (hello-service)

    GO111MODULE=on go run ./hello-service/main.go
    
  2. In another shell, start client (greeting-service)

    cd java-grpc/greeting-service
    mvnw clean spring-boot:run
    

Docker

Build
  1. Server (hello-service)

    docker build -t grpc/hello-service -f hello.Dockerfile .
    
  2. Client (greeting-service)

    docker build -t grpc/greeting-service -f greeting.Dockerfile .
    
Run
  1. Server (hello-service)

    docker run -ti --rm --name hello-service -p 50051:50051 grpc/hello-service
    
  2. Client (greeting-service)

    docker run -ti --rm --name greeting-service grpc/greeting-service
    

Kubernetes

Import container images
Minikube
  1. Enable Minikube internal container registry

    eval $(minikube docker-env)
    
  2. Build container images normally as it would be locally

KinD
  1. Build container images normally as it would be locally

  2. Import in KinD

    kind load docker-image grpc/hello-service
    kind load docker-image grpc/greeting-service
    
Deploy
  1. Start Kubernetes locally

    • Minikube

      minikube start --cpus 4 --memory 8192 --disk-size=10g
      
    • Kind

      kind create cluster --wait=60s
      
  2. Deploy server (hello-service)

    kubectl apply -k kube/hello-service
    
  3. Deploy client (greeting-service)

    kubectl apply -k kube/greeting-service
    
  4. Take a look of logs

    kubectl logs -l app=greeting-service -f
    

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL