Micro is a toolkit for cloud-native development.
Use go-micro to write services in Go or ja-micro for Java.
Micro addresses the key requirements for building cloud-native systems. It takes the microservice architecture pattern and transforms it into a set of tools which act as the building blocks for scalable platforms. Micro hides the complexity of distributed systems and provides well understood concepts to developers.
Micro builds on go-micro, making it a pluggable toolkit.
The toolkit is composed of the following features:
-
api
- API Gateway. A single HTTP entry point. Dynamic routing using service discovery. -
web
- Web Gateway and dashboard. Build web apps as microservices. -
cli
- Command line interface. Describe, query and interact directly from the terminal. -
bot
- Slack and hipchat bot. The CLI via messaging. -
new
- New template generation for services. -
run
- Runtime manager. Fetch, build and run from source in one command. -
sidecar
- A go-micro proxy. All the features of go-micro over HTTP.
For more detailed information on the architecture, installation and use of the toolkit checkout the docs.
See go-micro to start writing services.
go get -u github.com/micro/micro
Or via Docker
docker pull microhq/micro
Service discovery is the only dependency of the micro toolkit. Consul is set as the default.
Internally micro uses the go-micro registry for service discovery. This allows the toolkit to leverage go-micro plugins. Checkout go-plugins to swap out consul.
On Mac OS
brew install consul
consul agent -dev
Multicast DNS is built in for zero dependency service discovery.
Pass --registry=mdns
or set the env var MICRO_REGISTRY=mdns
for any command
## Use flag
micro --registry=mdns list services
## Use env var
MICRO_REGISTRY=mdns micro list services`
Let's test out the CLI
This is a greeter service written with go-micro. Make sure you're running service discovery.
go get github.com/micro/examples/greeter/srv && srv
Each service registers with discovery so we should be able to find it.
micro list services
Output
consul
go.micro.srv.greeter
Each service has a unique id, address and metadata.
micro get service go.micro.srv.greeter
Output
service go.micro.srv.greeter
version 1.0.0
Id Address Port Metadata
go.micro.srv.greeter-34c55534-368b-11e6-b732-68a86d0d36b6 192.168.1.66 62525 server=rpc,registry=consul,transport=http,broker=http
Endpoint: Say.Hello
Metadata: stream=false
Request: {
name string
}
Response: {
msg string
}
Make an RPC query via the CLI. The query is sent in json. We support json and protobuf out of the box.
micro query go.micro.srv.greeter Say.Hello '{"name": "John"}'
Output
{
"msg": "Hello John"
}
Look at the cli doc for more info.
Now let's test out the micro api
Run the greeter API. An API service logically separates frontends from backends.
go get github.com/micro/examples/greeter/api && api
The micro api is a single HTTP entry point which dynamically routes to rpc services.
micro api
Replicating the CLI call as a HTTP call
curl http://localhost:8080/greeter/say/hello?name=John
Output
{"message":"Hello John"}
Look at the api doc for more info.
Integrate go-micro plugins by simply linking them in a separate file
Create a plugins.go file
import (
// etcd v3 registry
_ "github.com/micro/go-plugins/registry/etcdv3"
// nats transport
_ "github.com/micro/go-plugins/transport/nats"
// kafka broker
_ "github.com/micro/go-plugins/broker/kafka"
)
Build binary
# For local use
go build -i -o micro ./main.go ./plugins.go
# For docker image
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags '-w' -i -o micro ./main.go ./plugins.go
Enable with flags or env vars
# flags
micro --registry=etcdv3 --transport=nats --broker=kafka [command]
# env vars
MICRO_REGISTRY=etcdv3 MICRO_TRANSPORT=nats MICRO_BROKER=kafka micro [command]
To learn more read the following micro content
- Docs - documentation and guides
- Toolkit - intro blog post about the toolkit
- Architecture & Design Patterns - details on micro patterns
- Presentation - Golang UK Conf 2016
- Twitter - follow us on Twitter
- Slack - join the slack community (1000+ members)
Project | Description |
---|---|
Dashboard | A react based micro dashboard |
Ja-micro | A micro compatible java framework |
Explore other projects at micro.mu/explore
Open source development of Micro is sponsored by Sixt