Creating your first microservice
A microservice is just a piece of code that runs as a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal, which we will be writing in this recipe using https://github.com/micro/micro
though there are a number of libraries available such as https://github.com/go-kit/kit
and https://github.com/grpc/grpc-go
, which serve the same purpose.
Getting ready…
- Start
consul agent
by executing the following command:
$ consul agent -dev
- Install and run
micro
by executing the following commands:
$ go get github.com/micro/micro $ micro api 2018/02/06 00:03:36 Registering RPC Handler at /rpc 2018/02/06 00:03:36 Registering API Default Handler at / 2018/02/06 00:03:36 Listening on [::]:8080 2018/02/06 00:03:36 Listening on [::]:54814 2018/02/06 00:03:36 Broker Listening on [::]:54815 2018/02/06 00:03:36 Registering node: go.micro.api-a6a82a54-0aaf-11e8-8d64-685b35d52676
How to do it…
- Create
first-greeting-service.go
inside...