Go to file
2015-05-25 17:19:13 +01:00
broker Publish/Subscribe with context 2015-05-23 23:16:26 +01:00
client Restructure go-micro layout and plugins 2015-05-23 20:04:16 +01:00
cmd Delete store, this is not a core requirement of microservices, will be included in go-platform 2015-05-25 17:19:13 +01:00
context Rework use of context 2015-05-23 11:53:40 +01:00
errors Fixes nil pointer dereference error 2015-01-30 16:03:17 +01:00
examples Publish/Subscribe with context 2015-05-23 23:16:26 +01:00
proto/health Fix health checker 2015-05-21 23:06:01 +01:00
registry Restructure go-micro layout and plugins 2015-05-23 20:04:16 +01:00
server Restructure go-micro layout and plugins 2015-05-23 20:04:16 +01:00
template update readme output 2015-05-23 12:22:23 +01:00
transport Restructure go-micro layout and plugins 2015-05-23 20:04:16 +01:00
LICENSE Add apache license 2015-02-27 09:38:47 +00:00
README.md Delete store, this is not a core requirement of microservices, will be included in go-platform 2015-05-25 17:19:13 +01:00

Go Micro

Go Micro is a microservices library which provides the fundamental building blocks for writing fault tolerant distributed systems at scale. It is part of the Micro toolchain.

An example server can be found in go-micro/template.

GoDoc

Features

  • Discovery
  • Client/Server
  • Pub/Sub

Planned

  • Metrics
  • Tracing
  • Logging
  • Stats

Prerequisites

Consul is the default discovery mechanism provided in go-micro. Discovery is however pluggable.

Install Consul

https://www.consul.io/intro/getting-started/install.html

Getting Started

Run Consul

$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul

Run Service

$ go run go-micro/template/main.go

I0523 12:21:09.506998   77096 server.go:113] Starting server go.micro.service.template id go.micro.service.template-cfc481fc-013d-11e5-bcdc-68a86d0d36b6
I0523 12:21:09.507281   77096 rpc_server.go:112] Listening on [::]:51868
I0523 12:21:09.507329   77096 server.go:95] Registering node: go.micro.service.template-cfc481fc-013d-11e5-bcdc-68a86d0d36b6

Test Service

$ go run go-micro/examples/service_client.go

go.micro.service.template-cfc481fc-013d-11e5-bcdc-68a86d0d36b6: Hello John

Writing a service

Create request/response proto

go-micro/template/proto/example/example.proto:

package go.micro.service.template.example;

message Request {
	required string name = 1;
}

message Response {
	required string msg = 1;
}

Compile proto protoc -I$GOPATH/src --go_out=$GOPATH/src $GOPATH/src/github.com/myodc/go-micro/template/proto/example/example.proto

Create request handler

go-micro/template/handler/example.go:

package handler

import (
	"code.google.com/p/go.net/context"
	"github.com/golang/protobuf/proto"

	"github.com/myodc/go-micro/server"
	example "github.com/myodc/go-micro/template/proto/example"
	log "github.com/golang/glog"
)

type Example struct{}

func (e *Example) Call(ctx context.Context, req *example.Request, rsp *example.Response) error {
	log.Info("Received Example.Call request")

	rsp.Msg = proto.String(server.Id + ": Hello " + req.GetName())

	return nil
}

Init server

go-micro/template/main.go:

package main

import (
	"github.com/myodc/go-micro/server"
	"github.com/myodc/go-micro/template/handler"
	log "github.com/golang/glog"
)

func main() {
	server.Name = "go.micro.service.template"

	// Initialise Server
	server.Init()

	// Register Handlers
	server.Register(
		server.NewReceiver(
			new(handler.Example),
		),
	)

	// Run server
	if err := server.Run(); err != nil {
		log.Fatal(err)
	}
}

Run service

$ go run go-micro/template/main.go

I0523 12:21:09.506998   77096 server.go:113] Starting server go.micro.service.template id go.micro.service.template-cfc481fc-013d-11e5-bcdc-68a86d0d36b6
I0523 12:21:09.507281   77096 rpc_server.go:112] Listening on [::]:51868
I0523 12:21:09.507329   77096 server.go:95] Registering node: go.micro.service.template-cfc481fc-013d-11e5-bcdc-68a86d0d36b6