1. Build project: Hello

$micro New –gopath=false Hello

├ ─ ─ main. Go ├ ─ ─ the generate. Go ├ ─ ─ plugin. Go ├ ─ ─ handler │ └ ─ ─ hello. Go ├ ─ ─ the subscriber │ └ ─ ─ hello. Go ├ ─ ─ proto │ └ ─ ─ the hello │ └ ─ ─ hello. Proto ├ ─ ─ Dockerfile ├ ─ ─ a Makefile ├ ─ ─ the README. Md ├ ─ ─ the gitignore └ ─ ─. Mod download protoc zip packages (protoc-$VERSION-$PLATFORM.zip) and install: visit https://github.com/protocolbuffers/protobuf/releases download protobuf for micro: go get -u github.com/golang/protobuf/proto go get -u github.com/golang/protobuf/protoc-gen-go go get github.com/micro/micro/v2/cmd/protoc-gen-micro compile the proto file hello.proto: cd hello make protoCopy the code
  1. Generate a Protobuf file

protoc --proto_path=proto --go_out=proto --micro_out=proto proto/hello.proto

  1. Start the service

$micro server $go run main.go // Start hello

go.micro.service.hello 2021-04-23 15:11:16 file=grpc/grpc.go:864 level=info Server [grpc] Listening on [::]:60735 2021-04-23 15:11:16 file= GRPC /grpc.go:881 Level =info Broker [HTTP] Connected to 127.0.0.1:60736 2021-04-23 15:11:16 file=grpc/grpc.go:697 level=info Registry [mdns] Registerin g node: go.micro.service.hello-190bc41b-94a3-4903-b892-01c3d67ac307 2021-04-23 15:11:17 file=grpc/grpc.go:730 level=info Subscribing to topic: go.micro.service.hello 2021-04-23 15:18:11 file=handler/hello.go:15 level=info Received Hello.Call requestCopy the code
  1. Service invocation test

$ go run cmd/cli/main.go

The 2021-04-23 15:18:11. 870405 I | call func success! Hello, xiao xie 2021-04-23 15:18:11. 972361 | I send MSG to success!Copy the code

Notes and documents