go-micro 示例服务入门 介绍
Go-Micro 是一个基于微服务库的可插拔 RPC,为编写分布式应用程序提供基本构件。它是
Micro 工具包的一部分,支持 Proto-RPC 和 JSON-RPC
的请求/响应协议,默认设置Consul为探索。
示例服务可以在 examples/service 找到。
特征
**特征** | **包** | **内置插件** | **描述** |
Discovery | [Registry](https://godoc.org/github.com/micro/go-micro/registry) | consul | 用来沟通的一种定位服务方式 |
Client | [Client](https://godoc.org/github.com/micro/go-micro/client) | rpc | 用来将RPC请求变成服务 |
Codec | [Codec](https://godoc.org/github.com/micro/go-micro/codec) | proto,json | 对请求进行编码/解码处理 |
Balancer | [Selector](https://godoc.org/github.com/micro/go-micro/selector) | random | 服务节点过滤和池 |
Server | [Server](https://godoc.org/github.com/micro/go-micro/server) | rpc | 监听和服务器的RPC请求 |
Pub/Sub | [Broker](https://godoc.org/github.com/micro/go-micro/broker) | http | 发布和订阅事件 |
Transport | [Transport](https://godoc.org/github.com/micro/go-micro/transport) | http | 服务之间的通信机制 |
示例服务
**项目** | **描述** |
[greeter](https://github.com/micro/micro/tree/master/examples/greeter) | greeter 服务(包括 Go、Ruby、Python ) |
[geo-srv](https://github.com/micro/geo-srv) | 使用 hailocab/go-geoindex 进行地理位置跟踪服务 |
[geo-api](https://github.com/micro/geo-api) | 为地理位置跟踪和搜索提供的 HTTP API 处理程序 |
[geocode-srv](https://github.com/micro/geocode-srv) | 使用 Google Geocoding API 提供地理编码服务 |
[hailo-srv](https://github.com/micro/hailo-srv) | 一种用于hailo出租车服务开发者的api服务 |
[place-srv](https://github.com/micro/place-srv) | 存储和检索地点的微服务 |
[slack-srv](https://github.com/micro/slack-srv) | 将Slack机器人的API当成一个go-micro 的RPC服务 |
[twitter-srv](https://github.com/micro/twitter-srv) | 一种用于Twitter的API微服务 |
[user-srv](https://github.com/micro/user-srv) | 一种为用户管理和认证提供的微服务 |
入门
这是一个以 greeter 服务为例的快速入门指南。
必备条件
我们需要一个服务发现机制来解决服务的名称到地址的映射 , 默认设置Consul为探索。Discovery是可插拔的,你可以使用
kubernetes, zookeeper 等。我们的实践可以在 go-plugins 上找到。
安装Consul
https://www.consul.io/intro/getting-started/install.html
运行 Consul
$ consul agent -dev -advertise=127.0.0.1
运行服务
$ go run examples/service/main.go 2016/03/14 10:59:14 Listening on [::]:50137 2016/03/14 10:59:14 Broker Listening on [::]:50138 2016/03/14 10:59:14 Registering node: greeter-ca62b017-e9d3-11e5-9bbb-68a86d0d36b6
测试服务
$ go run examples/service/main.go --client Hello John
go-micro 示例服务入门 官网
https://github.com/micro/go-micro
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。