Skip to content

Huangyan9188/micro

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Micro GoDoc Travis CI

Micro is a microservices toolkit. It simplifies writing and running distributed applications.

Checkout go-micro if you want to start writing services now.

Examples of how to write a service in ruby or python can be found in here

Overview

The goal of Micro is to provide a toolchain for microservice development and management. At the core, micro is simple and accessible enough that anyone can easily get started writing microservices. As you scale to hundreds of services, micro will provide the fundamental tools required to manage a microservice environment.

Features

  • Discovery
  • Client/Server
  • Pub/Sub
  • API Gateway
  • CLI
  • Web UI
  • Sidecar - for non Go native apps

Libraries & Tools

  • go-micro - A microservices client/server library based on http/rpc protobuf
  • api - A lightweight gateway/proxy for Micro based services
  • cli - A command line tool for micro
  • web - A simple web UI to observe micro services
  • sidecar - Integrate any application into the Micro ecosystem

Example Services

  • geo-srv - A go-micro based geolocation tracking service using hailocab/go-geoindex
  • geo-api - A HTTP API handler for geo location tracking and search
  • greeter - Greeter client/server examples in Go, ruby and python

Getting Started

Install

$ go get github.com/myodc/micro

Or via Docker

$ docker pull myodc/micro

Quick start

Run consul (default discovery mechanism)

$ go get github.com/hashicorp/consul
$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul

Run the greeter example app

$ go get github.com/myodc/micro/examples/greeter/server
$ server

List services

$ micro list services
consul
go.micro.srv.greeter

Get Service

$ micro get service go.micro.srv.greeter
go.micro.srv.greeter

Id	Address	Port	Metadata
go.micro.srv.greeter-154a6487-7d7e-11e5-882a-34363b77bace	[::]	57067	

Endpoint: Say.Hello
Metadata: stream=false
Request:
{
	name string
}
Response:
{
	msg string
}

Endpoint: Debug.Health
Metadata: stream=false
Request: {}
Response:
{
	status string
}

Query service

$ micro query go.micro.srv.greeter Say.Hello '{"name": "John"}'
{
	"msg": "go.micro.srv.greeter-154a6487-7d7e-11e5-882a-34363b77bace: Hello John"
}

Read more on how to use Micro here

Learn how to write and run a microservice using Go-Micro here

Usage

NAME:
   micro - A microservices toolchain

USAGE:
   micro [global options] command [command options] [arguments...]
   
VERSION:
   0.0.0
   
COMMANDS:
   api		Run the micro API
   registry	Query registry
   query	Query a service method using rpc
   health	Query the health of a service
   list		List items in registry
   get		Get item from registry
   sidecar	Run the micro sidecar
   web		Run the micro web app
   help, h	Shows a list of commands or help for one command
   
GLOBAL OPTIONS:
   --server_name 								Name of the server. go.micro.srv.example [$MICRO_SERVER_NAME]
   --server_id 									Id of the server. Auto-generated if not specified [$MICRO_SERVER_ID]
   --server_address ":0"							Bind address for the server. 127.0.0.1:8080 [$MICRO_SERVER_ADDRESS]
   --server_metadata [--server_metadata option --server_metadata option]	A list of key-value pairs defining metadata. version=1.0.0 [$MICRO_SERVER_METADATA]
   --broker "http"								Broker for pub/sub. http, nats, etc [$MICRO_BROKER]
   --broker_address 								Comma-separated list of broker addresses [$MICRO_BROKER_ADDRESS]
   --registry "consul"								Registry for discovery. kubernetes, consul, etc [$MICRO_REGISTRY]
   --registry_address 								Comma-separated list of registry addresses [$MICRO_REGISTRY_ADDRESS]
   --transport "http"								Transport mechanism used; http, rabbitmq, etc [$MICRO_TRANSPORT]
   --transport_address 								Comma-separated list of transport addresses [$MICRO_TRANSPORT_ADDRESS]
   --logtostderr								log to standard error instead of files
   --alsologtostderr								log to standard error as well as files
   --log_dir 									log files will be written to this directory instead of the default temporary directory
   --stderrthreshold 								logs at or above this threshold go to stderr
   -v 										log level for V logs
   --vmodule 									comma-separated list of pattern=N settings for file-filtered logging
   --log_backtrace_at 								when logging hits line file:N, emit a stack trace
   --help, -h	

About Microservices

Microservices is an architecture pattern used to decompose a single large application in to a smaller suite of services. Generally the goal is to create light weight services of 1000 lines of code or less. Each service alone provides a particular focused solution or set of solutions. These small services can be used as the foundational building blocks in the creation of a larger system.

The concept of microservices is not new, this is the reimagination of service orientied architecture but with an approach more holistically aligned with unix processes and pipes. For those of us with extensive experience in this field we're somewhat biased and feel this is an incredibly beneficial approach to system design at large and developer productivity.

Learn more about Microservices by watching Martin Fowler's presentation here or his blog post here.

Microservice Requirements

The foundation of a library enabling microservices is based around the following requirements:

  • Server - an ability to define handlers and serve requests
  • Client - an ability to make requests to another service
  • Discovery - a mechanism by which to discover other services

These 3 components form the minimum requirements for microservices development. An ecosystem of libraries and tools can be created around them to provide a feature rich system however at the foundation only these 3 things are required to write services and communicate between them.

Server

The server is the core component which allows you to register request handlers and serve requests. Ideally it's transport agnostic so different transports such as http, rabbitmq, etc can be chosen. On start it should register itself with discovery system so other microservices know it exists and deregister when shutting down. The server should handle encoding/decoding incoming/outgoing requests, leaving the handlers to operate on the request/response types they expect.

Example interface:

server.New(name, options) - instantiate new server
server.Register(handler) - register a handler with the server
server.Start() - start
server.Stop() - stop

Client

Where the server allows you to serve requests, the client lets you make them to other servers. The client should support request/response and pub/sub. Part of the microservices world is event driven programming, taking action based on events, which is why pub/sub is a requirement of the client. It should also make use of the discovery system so requests can be made by service name.

Example interface:

client.Request(name, request) - Make a request to another server
client.Publish(topic, message) - Publish a message on a topic
client.Subscribe(topic, channel) - Subscribe to a topic

Discovery

The discovery system is really vital to microservices development. Any sort of communication between servers will first require locating it and then making the request. Discovery should support registration and retrieval of servers. It should optionally support a keepalive mechanism to remove stale servers.

Example interface:

discovery.Register(name, hostname, ...) - Register a server
discovery.Deregister(name, hostname, ...) - Deregister a server
discovery.Get(name) - Get the details for a server
discovery.List() - List all servers

Resources

Roadmap & Future work

Features to be included as services

  • Config
  • Routing
  • Monitoring
  • Tracing
  • Logging

Releases

No releases published

Packages

No packages published

Languages

  • Go 98.0%
  • Protocol Buffer 2.0%