• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

GoMicro入门笔记

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Writing microservices with Go Micro

原文地址

Go Micro 定义:

  • Go语言实现
  • 插件化
  • 基于RPC

Go Micro 提供的接口:

  • 服务发现
  • 编码
  • Client/Server
  • 发布/订阅

Writing a service

1. Initialisation

micro.Flags

2. Defining the API

使用protobuf定义服务的接口。这种方式规范了api,并使用服务端与客户端接口保持一致。

greeter.proto

syntax = "proto3";

service Greeter {
	rpc Hello(HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
	string name = 1;
}

message HelloResponse {
	string greeting = 2;
}

上面示例proto 定义了一个服务的接口 handle Greeter,其有方法Hello,参数是 HelloRequest,返回HelloResponse

Generate the API interface

use protoc and protoc-gen-go
生成的protobuf 可以在 server 或者client的handler中使用

Implement the handler

在具体的service中,需要实现 proto 中的服务接口

Running the service

Writing a Client

客户端 也使用proto 的 handler 方法请求

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap