go-kit 入门(一)

go-kit 入门

1. microservice

Go-Kit

go kit 是一个分布式的开发工具集,在大型的组织(业务)中可以用来构建微服务。其解决了分布式系统中的大多数常见问题,因此,使用者可以将精力集中在业务逻辑上。

2. go-kit 组件介绍

2.1 Endpoint(端点)

Go kit首先解决了RPC消息模式。其使用了一个抽象的 endpoint 来为每一个RPC建立模型。

endpoint通过被一个server进行实现(implement),或是被一个client调用。这是很多 Go kit组件的基本构建代码块。

2.2 Circuit breaker(回路断路器)

Circuitbreaker(回路断路器) 模块提供了很多流行的回路断路lib的端点(endpoint)适配器。回路断路器可以避免雪崩,并且提高了针对间歇性错误的弹性。每一个client的端点都应该封装(wrapped)在回路断路器中。

2.3 Rate limiter(限流器)

ratelimit模块提供了到限流器代码包的端点适配器。限流器对服务端(server-client)和客户端(client-side)同等生效。使用限流器可以强制进、出请求量在阈值上限以下。

2.4 Transport(传输层)

transport 模块提供了将特定的序列化算法绑定到端点的辅助方法。当前,Go kit只针对JSON和HTTP提供了辅助方法。如果你的组织使用完整功能的传输层,典型的方案是使用Go在传输层提供的函数库,Go kit并不需要来做太多的事情。这些情况,可以查阅代码例子来理解如何为你的端点写一个适配器。目前,可以查看 addsvc的代码来理解Transport绑定是如何工作的。我们还提供了针对Thirft,gRPC,net/rpc,和http json的特殊例子。对JSON/RPC和Swagger的支持在计划中。

2.5 Logging(日志)

服务产生的日志是会被延迟消费(使用)的,或者是人或者是机器(来使用)。人可能会对调试错误、跟踪特殊的请求感兴趣。机器可能会对统计那些有趣的事件,或是对离线处理的结果进行聚合。这两种情况,日志消息的结构化和可操作性是很重要的。Go kit的 log 模块针对这些实践提供了最好的设计。

2.6 Metrics(Instrumentation)度量/仪表盘

直到服务经过了跟踪计数、延迟、健康状况和其他的周期性的或针对每个请求信息的仪表盘化,才能被认为是“生产环境”完备的。Go kit 的 metric 模块为你的服务提供了通用并健壮的接口集合。可以绑定到常用的后端服务,比如 expvarstatsdPrometheus

2.7 Request tracing(请求跟踪)

随着你的基础设施的增长,能够跟踪一个请求变得越来越重要,因为它可以在多个服务中进行穿梭并回到用户。Go kit的 tracing 模块提供了为端点和传输的增强性的绑定功能,以捕捉关于请求的信息,并把它们发送到跟踪系统中。(当前支持 Zipkin,计划支持Appdash

2.8 Service discovery and load balancing(服务发现和负载均衡)

如果你的服务调用了其他的服务,需要知道如何找到它(另一个服务),并且应该智能的将负载在这些发现的实例上铺开(即,让被发现的实例智能的分担服务压力)。Go kit的 loadbalancer模块提供了客户端端点的中间件来解决这类问题,无论你是使用的静态的主机名还是IP地址,或是 DNS的 SRV 记录,Consul,etcd 或是 Zookeeper。并且,如果你使用定制的系统,也可以非常容易的编写你自己的 Publisher,以使用 Go kit 提供的负载均衡策略。(目前,支持静态主机名、etcd、Consul、Zookeeper)

3 目标

  • 在各种SOA架构中操作–预期会与各种非Go kit服务进行交互
  • 使用RPC作为最主要的消息模式
  • 可插拔的序列化和传输–不仅仅只有JSON和HTTP
  • 简单便可融入现有的架构–没有任何特殊工具、技术的相关指令

4 目标之外(不考虑做的事情)

  • 支持除RPC之外的消息模式(至少目前是)–比如 MPI、pub/sub,CQRS,等
  • 除适配现有软件外,重新实现一些功能
  • 在运维方面进行评论:部署、配置、进程管理、服务编排等

5 依赖管理

Go kit 是一个函数库,设计的目标是引入到二进制文件中。对于二进制软件包的作者来讲,Vendoring是目前用来确保软件可靠、可重新构建的最好的机制。因此,我们强烈的建议我们的用户使用vendoring机制来管理他们软件的依赖,包括Go kit。

为了避免兼容性和可用性的问题,Go kit没有vendor它自己的依赖,并且并不推荐使用第三方的引用代理。

有一些工具可以让vendor机制更简单,包括 gbglidegvtgovendorvendetta。另外,Go kit使用了一系列的持续集成的机制来确保在尽快地修复那些复杂问题。

5 相关项目

标注有 ★ 的项目对 Go kit 的设计有着特别的影响 (反之亦然)

  1. 服务框架

    • gizmo, a microservice toolkit from The New York Times ★
    • go-micro, a microservices client/server library ★
    • gocircuit, dynamic cloud orchestration
    • gotalk, async peer communication protocol & library
    • h2, a microservices framework ★
    • Kite, a micro-service framework
  2. 独立组件

    afex/hystrix-go, client-side latency and fault tolerance library

    armon/go-metrics, library for exporting performance and runtime metrics to external metrics systems

    codahale/lunk, structured logging in the style of Google’s Dapper or Twitter’s Zipkin

    eapache/go-resiliency, resiliency patterns

    sasbury/logging, a tagged style of logging

    grpc/grpc-go, HTTP/2 based RPC

    inconshreveable/log15, simple, powerful logging for Go ★

    mailgun/vulcand, programmatic load balancer backed by etcd

    mattheath/phosphor, distributed system tracing

    pivotal-golang/lager, an opinionated logging library

    rubyist/circuitbreaker, circuit breaker library

    Sirupsen/logrus, structured, pluggable logging for Go ★

    sourcegraph/appdash, application tracing system based on Google’s Dapper

    spacemonkeygo/monitor, data collection, monitoring, instrumentation, and Zipkin client library

    streadway/handy, net/http handler filters

    vitess/rpcplus, package rpc + context.Context

    gdamore/mangos, nanomsg implementation in pure Go

  3. Web 框架

    Beego

    Gin

    Goji

    Gorilla

    Martini

    Negroni

    Revel (considered harmful)

  4. ###其他参考

    Architecting for the Cloud — Netflix

    Dapper, a Large-Scale Distributed Systems Tracing Infrastructure — Google

    Your Server as a Function (PDF) — Twitter

|2|left
此条目发表在GoLang, MircroService分类目录,贴了, , , 标签。将固定链接加入收藏夹。

go-kit 入门(一)》有 556 条评论

  1. Asking questions are really good thing if you are not understanding something entirely, however this paragraph presents pleasant understanding yet.

  2. cialis 20 mg说:

    Hello, for all time i used to check webpage posts here early in the dawn, because i like to find out more and more.

  3. This post is truly a fastidious one it assists new internet viewers, who are wishing for blogging.

  4. What a material of un-ambiguity and preserveness of valuable know-how regarding unexpected feelings.

  5. tadalafil说:

    Wow! It’s a nice jQuery script; I was also looking for that, therefore i got it right now from here. Keep it up admin.

  6. That’s genuinely a good video described within this post on the topic of how to write a post, therefore i got clear idea from here.

  7. Piece of writing writing is also a fun, if you be acquainted with afterward you can write or else it is complex to write.

  8. Its good comic YouTube video, I all the time go to pay a quick visit YouTube web site in support of humorous videos, since there is much more information available.

  9. Awesome YouTube video tutorials posted at this website, I am going to subscribe for regularly updates, as I don’t want to fail to take this series.

  10. One more thing that I wish for to share at this place is that, doesn’t matter what you are using free blogging service except if you don’t update your blog on on a regular basis basis then it’s no more importance.

  11. Hello everyone, I am sure you will be enjoying here by watching these kinds of funny videos.

  12. If you are going for finest contents like I do, simply pay a visit this web page daily because it provides quality contents, thanks

  13. Piece of writing writing is also a excitement, if you be acquainted with then you can write or else it is complicated to write.

  14. Remarkable! Its in fact amazing post, I have got much clear idea on the topic of from this paragraph.

  15. What’s up, how’s it going? Just shared this post with a colleague, we had a good laugh.

  16. Your way of explaining everything in this paragraph is actually fastidious, every one be able to effortlessly know it, Thanks a lot.

  17. What’s up, is it rite to simply study from books not to pay a quick visit world wide web for latest updates, what you say friends?

  18. Hahahaha, what a funny this YouTube film is! I’m still laughing, thanks to admin who had posted at this web page.

  19. Peculiar article, totally what I wanted to find.

  20. Wow! this cartoon type YouTube video I have viewed when I was in primary level and now I am in college and watching that again at this place.

  21. Hi colleagues, you are sharing your thoughts concerning web site Web optimization, I am also new user of web, thus I am also getting more from it. Thanks to the whole thing.

  22. I visited several websites except the audio feature for audio songs existing at this site is truly fabulous.

  23. Wow, nice YouTube video about how to set up virtual directory, I fully got it. Thanks keep it up.

  24. 20mg cialis说:

    All right you are correct, genuinely PHP is a open source and its help we can obtain free from any community forum or website as it takes place at this place at this web site.

  25. It’s not my first time to visit this web page, i am browsing this web site dailly and take good information from here all the time.

  26. cialis 5mg说:

    If you are going for most excellent contents like I do, only go to see this website everyday because it gives quality contents, thanks

  27. Can you please send an e-mail to me the code for this script or please tell me in detail concerning this script?

  28. cialis buy说:

    YouTube is world’s largest video sharing web page, no one can defeat it. Every one add videos at YouTube then obtain embed code and post anyplace.

  29. tadalafil说:

    Right away I am going away to do my breakfast, afterward having my breakfast coming again to read further news.

  30. 20 mg cialis说:

    Incredible quest there. What happened after? Thanks!

  31. Excellent, what a web site it is! This website provides valuable information to us, keep it up.

  32. YouTube video clips are well-known in whole globe, for the reason that it is the leading video sharing web site, and I become too happy by watching YouTube movies.

  33. Okay this YouTube video is much improved than previous one, this one has fastidious picture feature as well as audio.

  34. Hi there mates, I am for a second time at this place, and reading this post related to SEO, its also a fastidious piece of writing, so keep it up.

  35. Actually film is the presentation of some one’s feelings; it provides the lesson to the visitors.

  36. EllSype说:

    Buy Cialis Online Secure Propecia Sterility Rhineinc.In cialis cheapest online prices Ebay Precio De La Ciales Tadalis Sx Soft Order Online Acheter Cialis Sur Le Net

  37. blospek说:

    cialis generic sale
    cialis coupon
    alternative zyprexa cialis 20mg
    =http://cialissknrx.com/#”>cialis online

  38. plarown说:

    cialis 20mg rezeptfrei
    buy cheap cialis coupon
    get cialis online
    =http://cialissknrx.com/#”>buy cheap cialis online

  39. Duency说:

    generic cialis online pharmacy
    buy cialis
    substitute for cialis online pharmacy
    =http://cialissknrx.com/#”>cialis online

  40. Neency说:

    buy 20 mg cialis online
    buy cialis
    cialis online consultation
    =http://cialissknrx.com/#”>buy generic cialis

  41. Neency说:

    buy online cialis cialis
    cialis coupon
    cialis 5mg tablets cialis
    =http://cialissknrx.com/#”>buy cheap cialis online

  42. Wappyles说:

    cialis discount generic cialis
    generic cialis
    order cialis usa
    =http://cialisdenrx.com/#”>buy cialis online

  43. Exhani说:

    viagra v levitra cialis pills
    generic cialis online
    buy cialis in the uk
    =http://cialisdenrx.com/#”>buy cialis online

  44. driedge说:

    mixing cialis generic viagra
    generic cialis
    generic cialis 20mg best buy california
    =http://cialissknrx.com/#”>buy cialis online

  45. Vohycle说:

    buy tadalafil india
    buy cialis online
    canada cialis generic runny nose
    =http://cialisdenrx.com/#”>buy generic cialis

  46. utibra说:

    aetna cialis pills
    cheap cialis
    what are the best cialis pills
    =http://cialisdenrx.com/#”>buy cialis online

  47. What’s up, I just wanted to tell you, you’re wrong. Your article doesn’t make any sense.

  48. Eldese说:

    nitric oxide and cialis generic drugs
    buy cialis online
    buy cialis usa
    =http://cialissknrx.com/#”>cialis online

  49. Very nice article, just what I needed.

发表评论

电子邮件地址不会被公开。 必填项已用*标注