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. cialis 20说:

    Hello, I also would like to share my opinion at this time, when i don’t know even about a simple thing related to Personal home pages, I always go to explore that from net.

  2. cialis说:

    Hello, can any body help me how to get this video tutorial from this web page, I have watched and listen it at this time but would like to get it.

  3. Very descriptive blog, I enjoyed that bit. Will there be a part 2?

  4. cialis说:

    YouTube includes not only comical and humorous videos but also it contains learning related video lessons.

  5. cialis sale说:

    Sharing some thing is better than keeping up-to our self, so the YouTube video that is posted here I am going to share through my relatives and friends.

  6. Hahahaha, what a funny this YouTube film is! I am still laughing, thanks to admin who had posted at this site.

  7. YouTube is world’s biggest video sharing web page, no one can defeat it. Every one upload video tutorials at YouTube afterward obtain embed code and post everywhere.

  8. cialis daily说:

    This is my first time pay a quick visit at here and i am actually impressed to read everthing at single place.

  9. Really film is the display of some one’s feelings; it gives the lesson to the users.

  10. It’s wonderful that you are getting thoughts from this post as well as from our discussion made at this place.

  11. tadalafil说:

    My family every time say that I am killing my time here at web, but I know I am getting familiarity every day by reading such good content.

  12. Since the admin of this web page is working, no hesitation very rapidly it will be famous, due to its feature contents.

  13. If some one wishes expert view concerning blogging and site-building afterward i suggest him/her to pay a quick visit this website, Keep up the good job.

  14. cialis uk说:

    I am keen of learning Flash, is there any post associated to Flash, if yes, then please post it, thanks.

  15. No one can deny from the feature of this video posted at this web page, nice work, keep it all the time.

  16. cialis cost说:

    Hello every buddy, it’s a enormous fun at here viewing these funny YouTube video lessons at at this place, pleasant stuff, thanks to admin of this site

  17. One other technique in favor of promoting your website is posting comments on unique directories with your website link.

  18. Hi every buddy, it’s a wonderful entertaining at at this place watching these funny YouTube video lessons at at this place, pleasant data, thanks to admin

  19. cialis uk说:

    What’s up colleagues, good paragraph and good arguments commented at this place, I am really enjoying by these.

  20. This video post is really fantastic, the noise feature and the picture feature of this video post is truly remarkable.

  21. I and my colleagues watch the soccer game clips at YouTube all the time, since they have in pleasant quality.

  22. Why YouTube video clips are shared everywhere? I think one cause is that these are straightforward to take embed script and paste that code anyplace you want.

  23. |When I wish for to place gallery or LightBox or even a slider on my web site I every time attempt to use jQuery script in support of that.

  24. buy cialis说:

    |When I wish for to place gallery or LightBox or yet a slider on my web site I forever try to use jQuery script for that.

  25. I think a visualized display can be enhanced then simply a simple text, if information are defined in pictures one can simply be familiar with these.

  26. tadalafil说:

    Hi there to all, the YouTube film that is posted at at this place has genuinely pleasant quality along with good audio quality

  27. Your means of telling all in this article is truly nice, every one be able to effortlessly be aware of it, Thanks a lot.

  28. Hi there everyone, I am sure you will be enjoying here by watching these comical video lessons.

  29. If you want to increase your know-how just keep visiting this site and be updated with the most up-to-date information posted here.

  30. Highly energetic article, I liked that bit. Will there be a part 2?

  31. When some one searches for his essential thing, therefore he/she wishes to be available that in detail, so that thing is maintained over here.

  32. Oh! Wow its genuinely a funny and jockey YouTube video posted here. thanks for sharing it.

  33. YouTube contains not simply comical and humorous video lessons but also it contains educational related movies.

  34. One additional method in favor of advertising your blog is posting comments on different sites with your weblog link.

  35. Wow, this piece of writing is fastidious, my younger sister is analyzing these kinds of things, so I am going to tell her.

  36. If any one wants to be a successful blogger, then he/she must look at this post, since it includes al} strategies related to that.

  37. Appreciation to my father who told me about this weblog, this web site is in fact amazing.

  38. There are also so many video uploading web pages, and these as well provide facility for sharing their video tutorials, however I think YouTube is the best.

  39. It is the happiest day of my life so far, when I am watching these} funny movies at this place, since after full day working I was so tired and now feeling fine.

  40. If you apply these kinds of methods for increasing traffic on your own weblog, I am obviously you will see the difference in few days.

  41. It’s really very complex in this full of activity life to listen news on TV, therefore I just use web for that purpose, and get the newest news.

  42. Hi there dear, me and my mom are as well watch comic video clips except after I done my homework

  43. Thanks to my father who informed me concerning this web site, this webpage is actually remarkable.

  44. Wow! Finally I got a webpage from where I be capable of in fact get valuable information concerning my study and knowledge.

  45. Hello everybody, I know YouTube video contains less bytes of memory due to that its quality is poor, however this YouTube video has impressive picture features.

  46. What a funny blog! I actually loved watching this funny video with my relatives as well as including my colleagues.

  47. One more thing that I would like to share at this time is that, whatever you are using free blogging service but if you don’t update your blog on daily basis then it’s no more worth.

发表评论

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