Micro

Micro 是一个云端原生开发平台。「Micro is a cloud native development platform」

Github stars Tracking Chart

Micro

概述

Micro 解决了在云中构建服务的关键需求。它利用微服务架构模式,并提供一套服务,作为平台的构件。Micro 处理了分布式系统的复杂性,并提供了更简单的可编程抽象来构建。

内容

  • 简介 -- Micro 的高层次介绍
  • 入门 -- helloworld 快速入门指南
  • 升级指南 -- 更新您的 go-micro 项目以使用micro v3。
  • 架构 -- 描述了架构、设计和权衡。
  • 参考资料 -- Micro CLI和服务的深度参考资料。
  • 资源 -- 外部资源和贡献
  • 路线图 -- 我们的长期议程上的事情。
  • 用户 -- 在生产中使用 Micro 的开发人员和公司。
  • FAQ -- 常见问题
  • Blog -- 我们的最新信息

特性

以下是组成 Micro 的核心组件。

服务器

Micro 是作为一个微服务架构构建的,并抽象出底层基础设施的复杂性。我们将其作为一个面向用户的单一逻辑服务器,但将其分解为各种可插入任何底层系统的构件基元。

服务器由以下服务组成:

  • API -- HTTP 网关,它使用基于路径的解析方式将 http/json 请求动态映射到 RPC。
  • Auth -- 使用 jwt 令牌和基于规则的访问控制进行开箱即用的认证和授权。
  • Broker -- 用于异步通信和分发通知的短暂的 pubsub 消息传递。
  • Config -- 服务级配置的动态配置和秘密管理,无需重启。
  • Events -- 具有有序信息传递、偏移重播和持久存储的事件流。
  • Network -- 所有内部请求流量的服务间联网、隔离和路由平面。
  • Proxy -- 用于远程访问和任何外部 grpc 请求流量的身份识别代理。
  • Runtime -- 服务生命周期和流程管理,支持从源头到运行的自动构建。
  • Registry -- 集中式服务发现和 API 端点探索器,具有丰富的元数据功能。
  • Store -- 具有 TTL 过期和持久化 crud 的 Key-Value 存储,以保持微服务的无状态。
架构

Micro 现在还包含了令人难以置信的流行的 Go Micro 框架,它内置在服务开发中。Go 框架使你的服务编写变得非常简单,而无需拼凑成一行行的模板。自动配置和默认初始化,只需导入并快速开始。

命令行

Micro 不仅带来了丰富的架构模型,还为该需求量身定制了命令行体验。命令行界面包括平台上运行的所有服务的动态命令映射。将任何服务瞬间变成 CLI 命令以及输入的标志解析。包括对多个环境和命名空间的支持,自动刷新认证证书,创建和运行服务,状态信息和日志流,以及更多等等。

环境

最后,Micro 通过命名空间加入了环境和多租户的概念。在本地运行你的服务器用于开发,在云端运行用于暂存和生产,使用 CLI 命令 micro env set [environment] 和 micro user set [namespace] 在它们之间无缝切换。

安装

从源代码安装
go get github.com/micro/micro/v3

用 Docker 安装
# install
docker pull micro/micro

# run it
docker run -p 8080-8081:8080-8081/tcp micro/micro server
Helm Chart
helm repo add micro https://micro.github.io/helm
helm install micro micro/micro
二进制发布文件
# MacOS
curl -fsSL https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh | /bin/bash

# Linux
wget -q  https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh -O - | /bin/bash

# Windows
powershell -Command "iwr -useb https://raw.githubusercontent.com/micro/micro/master/scripts/install.ps1 | iex"

入门

在本地运行服务器

micro server

将环境设置为本地(127.0.0.1:8081)

micro env set local

登录服务器

# user: admin pass: micro
micro login

创建服务

# generate a service (follow instructions in output)
micro new helloworld

# run the service
micro run helloworld

# check the status
micro status

# list running services
micro services

# call the service
micro helloworld --name=Alice

# curl via the api
curl -d '{"name": "Alice"}' http://localhost:8080/helloworld

服务示例

Micro 包含了一个 Go 框架,用于为核心 IDL 和传输写服务包装 gRPC。

在 proto 中定义服务:

syntax = "proto3";

package helloworld;

service Helloworld {
    rpc Call(Request) returns (Response) {}
}

message Request {
    string name = 1;
}

message Response {
    string msg = 1;
}

用 Go 写它们:

package main

import (
    "context"
  
    "github.com/micro/micro/v3/service"
    "github.com/micro/micro/v3/service/logger"
    pb "github.com/micro/services/helloworld/proto"
)

type Helloworld struct{}

// Call is a single request handler called via client.Call or the generated client code
func (h *Helloworld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
    logger.Info("Received Helloworld.Call request")
    rsp.Msg = "Hello " + req.Name
    return nil
}

func main() {
    // Create service
    srv := service.New(
        service.Name("helloworld"),
    )

    // Register Handler
    srv.Handle(new(Helloworld))

    // Run the service
    if err := srv.Run(); err != nil {
        logger.Fatal(err)
    }
}

客户端调用

import (
    "context"
  
    "github.com/micro/micro/v3/service/client"
    pb "github.com/micro/services/helloworld/proto"
)

// create a new helloworld service client
helloworld := pb.NewHelloworldService("helloworld", client.DefaultClient) 

// call the endpoint Helloworld.Call
rsp, err := helloworld.Call(context.Background(), &pb.Request{Name: "Alice"})

Curl 访问 API

curl http://localhost:8080/helloworld?name=Alice

使用方法

有关平台的架构、安装和使用的详细信息,请参见 文档

许可证

请参阅使用 Polyform ShieldLICENSE

托管

对于托管的微平台又名M3O,请参见 m3o.com

社区

在 GitHub 讨论Slack 上加入我们。


(The second edition revised by vz on 2021.4.9)


Overview

Name With Ownermicro/micro
Primary LanguageGo
Program languageGo (Language Count: 7)
PlatformLinux, Mac, Windows, Docker
License:Apache License 2.0
Release Count139
Last Release Namev4.6.0 (Posted on 2024-04-25 08:36:40)
First Release Namev0.1.0 (Posted on 2017-06-12 12:48:21)
Created At2015-01-16 22:35:14
Pushed At2024-04-28 06:49:26
Last Commit At2024-04-28 14:49:26
Stargazers Count12k
Watchers Count318
Fork Count1k
Commits Count4.9k
Has Issues Enabled
Issues Count579
Issue Open Count27
Pull Requests Count1297
Pull Requests Open Count0
Pull Requests Close Count157
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Micro License Go Report Card Slack M3O

Overview

Micro addresses the key requirements for building services in the cloud. It leverages the microservices
architecture pattern and provides a set of services which act as the building blocks of a platform. Micro deals
with the complexity of distributed systems and provides simpler programmable abstractions to build on.

Contents

  • Introduction - A high level introduction to Micro
  • Getting Started - The helloworld quickstart guide
  • Upgrade Guide - Update your go-micro project to use micro v3.
  • Architecture - Describes the architecture, design and tradeoffs
  • Reference - In-depth reference for Micro CLI and services
  • Resources - External resources and contributions
  • Roadmap - Stuff on our agenda over the long haul
  • Users - Developers and companies using Micro in production
  • FAQ - Frequently asked questions
  • Blog - For the latest from us

Features

Below are the core components that make up Micro.

Server

Micro is built as a microservices architecture and abstracts away the complexity of the underlying infrastructure. We compose
this as a single logical server to the user but decompose that into the various building block primitives that can be plugged
into any underlying system.

The server is composed of the following services.

  • API - HTTP Gateway which dynamically maps http/json requests to RPC using path based resolution
  • Auth - Authentication and authorization out of the box using jwt tokens and rule based access control.
  • Broker - Ephemeral pubsub messaging for asynchronous communication and distributing notifications
  • Config - Dynamic configuration and secrets management for service level config without the need to restart
  • Events - Event streaming with ordered messaging, replay from offsets and persistent storage
  • Network - Inter-service networking, isolation and routing plane for all internal request traffic
  • Proxy - An identity aware proxy used for remote access and any external grpc request traffic
  • Runtime - Service lifecycle and process management with support for source to running auto build
  • Registry - Centralised service discovery and API endpoint explorer with feature rich metadata
  • Store - Key-Value storage with TTL expiry and persistent crud to keep microservices stateless

Framework

Micro additionally now contains the incredibly popular Go Micro framework built in for service development.
The Go framework makes it drop dead simple to write your services without having to piece together lines and lines of boilerplate. Auto
configured and initialised by default, just import and get started quickly.

Command Line

Micro brings not only a rich architectural model but a command line experience tailored for that need. The command line interface includes
dynamic command mapping for all services running on the platform. Turns any service instantly into a CLI command along with flag parsing
for inputs. Includes support for multiple environments and namespaces, automatic refreshing of auth credentials, creating and running
services, status info and log streaming, plus much, much more.

Environments

Finally Micro bakes in the concept of Environments and multi-tenancy through Namespaces. Run your server locally for
development and in the cloud for staging and production, seamlessly switch between them using the CLI commands micro env set [environment]
and micro user set [namespace].

Install

From Source

go get github.com/micro/micro/v3

Using Docker

# install
docker pull micro/micro

# run it
docker run -p 8080-8081:8080-8081/tcp micro/micro server

Helm Chart

helm repo add micro https://micro.github.io/helm
helm install micro micro/micro

Release binaries

# MacOS
curl -fsSL https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh | /bin/bash

# Linux
wget -q  https://raw.githubusercontent.com/micro/micro/master/scripts/install.sh -O - | /bin/bash

# Windows
powershell -Command "iwr -useb https://raw.githubusercontent.com/micro/micro/master/scripts/install.ps1 | iex"

Getting Started

Run the server locally

micro server

Set the environment to local (127.0.0.1:8081)

micro env set local

Login to the server

# user: admin pass: micro
micro login

Create a service

# generate a service (follow instructions in output)
micro new helloworld

# run the service
micro run helloworld

# check the status
micro status

# list running services
micro services

# call the service
micro helloworld --name=Alice

# curl via the api
curl -d '{"name": "Alice"}' http://localhost:8080/helloworld

Example Service

Micro includes a Go framework for writing services wrapping gRPC for the core IDL and transport.

Define services in proto:

syntax = "proto3";

package helloworld;

service Helloworld {
	rpc Call(Request) returns (Response) {}
}

message Request {
	string name = 1;
}

message Response {
	string msg = 1;
}

Write them using Go:

package main

import (
	"context"
  
	"github.com/micro/micro/v3/service"
	"github.com/micro/micro/v3/service/logger"
	pb "github.com/micro/services/helloworld/proto"
)

type Helloworld struct{}

// Call is a single request handler called via client.Call or the generated client code
func (h *Helloworld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
	logger.Info("Received Helloworld.Call request")
	rsp.Msg = "Hello " + req.Name
	return nil
}

func main() {
	// Create service
	srv := service.New(
		service.Name("helloworld"),
	)

	// Register Handler
	srv.Handle(new(Helloworld))

	// Run the service
	if err := srv.Run(); err != nil {
		logger.Fatal(err)
	}
}

Call with the client:

import (
	"context"
  
	"github.com/micro/micro/v3/service/client"
	pb "github.com/micro/services/helloworld/proto"
)

// create a new helloworld service client
helloworld := pb.NewHelloworldService("helloworld", client.DefaultClient) 

// call the endpoint Helloworld.Call
rsp, err := helloworld.Call(context.Background(), &pb.Request{Name: "Alice"})

Curl it via the API

curl http://localhost:8080/helloworld?name=Alice

Usage

See the docs for detailed information on the architecture, installation and use of the platform.

License

See LICENSE which makes use of Polyform Shield.

Hosting

For the hosted Micro Platform aka M3O see m3o.com.

Community

Join us on GitHub Discussions or Slack.

To the top