Micro Examples

通过例子学习 micro。(Learn micro by example)

Github stars Tracking Chart

这是一个micro 示例的存储库。请随意贡献。

内容

  • api - 提供API使用示例
  • 预订 - booking.com演示应用程序
  • 经纪商 - 使用经纪商进行发布和订阅的示例。
  • 客户端 - 使用客户端软件包来调用服务。
  • 命令 - bot命令作为微服务的一个例子
  • 事件 - 使用API网关事件处理程序
  • 标志 - 将命令行标志用于服务
  • 表单 - 如何解析micro api背后的表单
  • 函数 - 使用函数编程模型的示例
  • 优雅 - 演示正常关闭服务
  • greeter - 一个完整的greeter示例(包括python,ruby示例)
  • 心跳 - 通过发现使服务保持心跳状态以实现高可用性
  • 元数据 - 从请求的上下文中提取元数据
  • 选项 - 在go-micro框架中设置选项
  • 插件 - 如何使用插件
  • pubsub - 在客户端/服务器级别使用pubsub的示例
  • grpc - 如何使用 go-grpc 的示例
  • 重定向 - 如何使用API服务进行http重定向的示例
  • roundrobin - 真正的循环式请求的有状态客户端封装器
  • 安全 - 演示如何使用传输安全选项进行自签名证书
  • 服务器 - 将服务器软件包直接用于服务器请求。
  • 服务 - go-micro中顶级服务的示例。
  • 分片 - 如何分割请求或使用会话亲和力的示例
  • 关机 - 通过取消上下文来演示正常关机
  • 边车 - 使用多种语言边车的迎宾服务
  • - 流媒体服务和客户端的示例
  • 模板 - 使用“微新”命令生成的Api,web和srv服务模板
  • 等待组 - 演示如何在服务中使用等待组
  • 包装 - 使用日志包装器的简单示例

外部

社区

通过资源管理器查找社区的贡献

  • 去购物 - 带有一系列服务的示例产品

依赖关系

服务发现

所有的服务都需要服务发现。默认是Consul或MDNS。

Consul

安装

brew install consul

运行

consul agent -dev

多播DNS

使用 flag --registry=mdns 获得零依赖性配置

Protobuf

Protobuf用于消息类型和客户端/手柄存根的代码生成。

如果进行更改,请重新编译原型。

安装

go get github.com/golang/protobuf/{proto,protoc-gen-go}
go get github.com/micro/protoc-gen-micro

编译Proto

protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=. path/to/proto

Overview

Name With Ownermicro/services
Primary LanguageGo
Program languageDockerfile (Language Count: 4)
PlatformBSD, Linux, Mac, Windows
License:Apache License 2.0
Release Count27
Last Release Namev3.0.0 (Posted on 2024-04-25 08:50:05)
First Release Namev0.11.0 (Posted on 2020-10-02 11:13:12)
Created At2020-10-02 10:14:01
Pushed At2024-04-25 07:50:17
Last Commit At2024-04-25 08:49:34
Stargazers Count1.2k
Watchers Count17
Fork Count134
Commits Count1.7k
Has Issues Enabled
Issues Count91
Issue Open Count44
Pull Requests Count317
Pull Requests Open Count0
Pull Requests Close Count23
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Micro Examples Travis CI Go Report Card

This is a repository for micro examples. Feel free to contribute.

i18n

中文版本

Contents

Most likely needed examples

  • service - A sample micro service
  • greeter - A complete greeter example
  • booking - A demo end to end application

Other

  • api - Provides API usage examples
  • booking - A booking.com demo application
  • broker - A example of using Broker for Publish and Subscribing.
  • client - Usage of the Client package to call a service.
  • command - An example of bot commands as micro services
  • config - Using Go Config for dynamic config
  • event - Using the API Gateway event handler
  • filter - Filter nodes of a service when requesting
  • flags - Using command line flags with a service
  • form - How to parse a form behind the micro api
  • function - Example of using Function programming model
  • getip - Get the local and remote ip from metadata
  • graceful - Demonstrates graceful shutdown of a service
  • greeter - A complete greeter example (includes python, ruby examples)
  • heartbeat - Make services heartbeat with discovery for high availability
  • helloworld - Hello world using micro
  • kubernetes - Examples of using the k8s registry and grpc
  • metadata - Extracting metadata from context of a request
  • mocking - Demonstrate mocking helloworld service
  • noproto - Use micro without protobuf or code generation, only go types
  • options - Setting options in the go-micro framework
  • plugins - How to use plugins
  • pubsub - Example of using pubsub at the client/server level
  • grpc - Examples of how to use go-micro/service/grpc
  • redirect - An example of how to http redirect using an API service
  • roundrobin - A stateful client wrapper for true round robin of requests
  • secure - Demonstrates use of transport secure option for self signed certs
  • server - Use of the Server package directly to server requests.
  • service - Example of the top level Service in go-micro.
  • sharding - An example of how to shard requests or use session affinity
  • shutdown - Demonstrates graceful shutdown via context cancellation
  • stream - An example of a streaming service and client
  • template - Api, web and srv service templates generated with the 'micro new' command
  • tunnel - How to use connection tunneling with the tunnel package
  • waitgroup - Demonstrates how to use a waitgroup with a service
  • wrapper - A simple example of using a log wrapper

Community

Find contributions from the community via the explorer

  • go-shopping - A sample product with a suite of services
  • shippy - A multi app demo and tutorial
  • microhq - A place for micro services

Dependencies

Service Discovery

All services require service discovery. The default is multicast DNS, a zeroconf system.

If you need something multi-host or more resilient use consul.

Consul

# install
brew install consul

# run
consul agent -dev

Use flag --registry=consul to enable the consul registry.

Protobuf

Protobuf is used for code generation of message types and client/hander stubs.

If making changes recompile the protos.

Install

Install protoc for your environment. Then:

go get github.com/golang/protobuf/{proto,protoc-gen-go}
go get github.com/micro/protoc-gen-micro

Compile Proto

protoc --proto_path=$GOPATH/src:. --micro_out=. --go_out=. path/to/proto
To the top