Slide 1

Slide 1 text

1 All The Things Michael Hamrah @mhamrah / Chief Architect @NamelyHR

Slide 2

Slide 2 text

Get The Code 2 https://github.com/mhamrah/grpc-example

Slide 3

Slide 3 text

Agenda 3 gRPC Overview Working with gRPC Http and Json Support Google Cloud Endpoints Kubernetes GraphQL https://github.com/mhamrah/grpc-example

Slide 4

Slide 4 text

Should we build microservices? 4 ?

Slide 5

Slide 5 text

5 Bounded Context Abstraction Cruft

Slide 6

Slide 6 text

gRPC 6 IDL w/ Multi-Language Efficient Serialization Plugin w/ protoc Forwards/Backwards Compatible Self-Describing

Slide 7

Slide 7 text

IDL FTW 7 service Todos { // GetTodo returns a list of ToDos rpc GetTodo (GetTodoRequest) returns (Todo) {} } message Todo { string id = 1; string title = 2; bool completed = 3; } message GetTodoRequest { string id = 1; }

Slide 8

Slide 8 text

CodeGen 8 $ docker run -v `pwd`:/defs \ namely/protoc-all:1.14_0 \ -f todos.proto -l go

Slide 9

Slide 9 text

Gen’d Code .gitignored! 9 type TodosServer interface { // GetTodo returns a single todo based on an id GetTodo(context.Context, *GetTodoRequest) (*Todo, error) } func RegisterTodosServer( s *grpc.Server, srv TodosServer) { ... }

Slide 10

Slide 10 text

Service Logic 10 type Server struct { storage Storage } func (s *Server) GetTodo( ctx context.Context, in *pb.GetTodoRequest ) (*pb.Todo, error) { return s.storage.Read(ctx, in.Id) } todos/server/todos.go

Slide 11

Slide 11 text

Server Code 11 lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 50051)) grpcServer := grpc.NewServer() pb.RegisterTodosServer( grpcServer, todos.NewServer( todos.MemoryStorage{} ) ) reflection.Register(grpcServer) grpcServer.Serve(lis) todos/server/cmd/main.go

Slide 12

Slide 12 text

Client Code 12 conn, _ := grpc.Dial( cfg.GetString("backend"), grpc.WithInsecure()) defer conn.Close() client := pb.NewTodosClient(conn) resp, err := client.CreateTodo( context.Background(), &pb.CreateTodoRequest{ Todo: &pb.Todo {Title: "foo"} }) fmt.Println("%v", resp.id) todos/client/cmd/main.go

Slide 13

Slide 13 text

# grpc_cli ls todos:50051 todos.Todos ListTodos GetTodo CreateTodo UpdateTodo DeleteTodo DeleteAllTodos

Slide 14

Slide 14 text

# grpc_cli call todos:50051 \ todos.Todos.CreateTodo 'todo: { title:"foo" }' connecting to todos:50051 id: "01CPBT4FWY3SHPK55B355DKEZQ" title: "foo" Rpc succeeded with OK status

Slide 15

Slide 15 text

15 Is One Of Many Your Service

Slide 16

Slide 16 text

Small Surfaces Include Events Style Guide https://cloud.google.com/apis/design/ Be Resourceful Be Consistent 16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

I Can Web? The Beauty of IDLs 18

Slide 19

Slide 19 text

$ docker run -v `pwd`:/defs \ namely/gen-grpc-gateway -f todos.proto -s Todos $ docker build -t todos-gateway gen/grpc-gateway rpc UpdateTodo (UpdateTodoRequest) returns (Todo ) { option (google.api.http) = { patch: "/todos/{todo.id}" body: "todo" }; } grpc-gateway gRPC HTTP Call

Slide 20

Slide 20 text

# curl todos-gw/todos -d '{ "todo": { "title": "foo" } }' {"id":"01CPDF3X4E73J3FC6T8XVWVTE9"} # curl todos-gw/swagger.json { … }

Slide 21

Slide 21 text

Google Cloud Endpoints 21 API

Slide 22

Slide 22 text

More IDL Fun todos.proto descriptor.proto 22 $ protoc -I . \ --descriptor_set_out=gen/api_descriptor.pb \ --include_source_info --include_imports todos.proto

Slide 23

Slide 23 text

Yaml Config 23 $ gcloud endpoints services deploy \ gen/api_descriptor.pb \ gcp-endpoints/api_config.yaml type: google.api.Service config_version: 3 name: todos.endpoints.grpc-demo-1.cloud.goog title: Todos gRPC API apis: - name: todos.Todos usage: rules: - selector: "*" allow_unregistered_calls: true

Slide 24

Slide 24 text

ESP Sidecar github.com/cloudendpoints/esp 24 Service ESP Endpoints

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

26

Slide 27

Slide 27 text

Stitching With Ingress 27 apiVersion: extensions/v1beta1 kind: Ingress metadata: name: app-ingress spec: rules: - http: paths: - path: /todos backend: serviceName: todos-server servicePort: 8080 - path: /users backend: serviceName: users-server servicePort: 8080

Slide 28

Slide 28 text

GraphQL w/ Rejoiner github.com/google/rejoiner 28 GraphQL Rejoiner gRPC gRPC

Slide 29

Slide 29 text

private static final GraphQLSchema SCHEMA = Guice.createInjector( new SchemaProviderModule(), new TodosClientModule(), new TodosSchemaModule()) .getInstance(Key.get(GraphQLSchema.class, Schema.class)); final class TodosSchemaModule extends SchemaModule { @Query("todo") Todo getTodo(GetTodoRequest request, TodosGrpc.TodosBlockingStub client) { return client.getTodo(request); } }

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

THANKS! Any questions? You can find me at @mhamrah & [email protected] 31