Creating your second microservice
In this recipe, we will create another microservice using go-micro, which is a replica of the first-greeting-service.go except for the logger message printed on the console that demonstrates the concept of client-side load balancing between the two different instances of a service with the same name.
How to do it…
- Create
second-greeting-service.goinside theservicesdirectory by executing the command$ cd services && touch second-greeting-service.go. - Copy the following content to
second-greeting-service.go:
package main
import
(
"context"
"log"
"time"
hello "../proto"
"github.com/micro/go-micro"
)
type Say struct{}
func (s *Say) Hello(ctx context.Context, req *hello.Request,
rsp *hello.Response) error
{
log.Print("Received Say.Hello request - second greeting
service")
rsp.Msg = "Hello " + req.Name
return nil
}
func main()
{
service := micro.NewService
(
micro.Name("go.micro.service.greeter"),
micro.RegisterTTL(time...