摘要: package Services import ( "context" "fmt" "github.com/go-kit/kit/endpoint" "github.com/go-kit/kit/log" "golang.org/x/time/rate" "gomicro/utils" "os" "strconv" ) typ... 阅读全文
posted @ 2019-12-23 23:15 离地最远的星 阅读(485) 评论(0) 推荐(0) 编辑
摘要: 熔断器一般部署在客户端或者网关里面 封装到服务端 package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "gomicro2/util" "log" "time" ) func main() { configA := hystrix.CommandConfig{... 阅读全文
posted @ 2019-12-23 21:57 离地最远的星 阅读(374) 评论(0) 推荐(0) 编辑
摘要: package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "sync" "time" ) type Product struct { ID int Title string Price int } func getPro... 阅读全文
posted @ 2019-12-23 19:35 离地最远的星 阅读(1585) 评论(0) 推荐(0) 编辑
摘要: 熔断器控制最大并发数 package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "sync" "time" ) type Product struct { ID int Title string Price int } fun... 阅读全文
posted @ 2019-12-23 16:41 离地最远的星 阅读(413) 评论(0) 推荐(0) 编辑
摘要: 异步执行和服务降级,使用hystrix.Go()函数的返回值是chan err package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string ... 阅读全文
posted @ 2019-12-23 16:05 离地最远的星 阅读(341) 评论(0) 推荐(0) 编辑
摘要: 在hystrix的超时回调函数中处理超时推荐其他商品 package main import ( "errors" "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string ... 阅读全文
posted @ 2019-12-23 15:51 离地最远的星 阅读(401) 评论(0) 推荐(0) 编辑
摘要: ## 使用hystrix来实现监控超时 ```go package main import ( "fmt" "github.com/afex/hystrix-go/hystrix" "math/rand" "time" ) type Product struct { ID int Title string Price int... 阅读全文
posted @ 2019-12-23 15:34 离地最远的星 阅读(788) 评论(0) 推荐(0) 编辑
摘要: 简单来说就是浏览器想要拿到最终的结果需要需要经过A,B,C三个节点,A调用B,B调用C最终返回结果,但是如果C崩溃了,我们应该怎么做呢 先模拟一个延迟调用的例子 package main import ( "fmt" "math/rand" "time" ) type Product struct { ID int Title st... 阅读全文
posted @ 2019-12-23 15:20 离地最远的星 阅读(328) 评论(0) 推荐(0) 编辑
摘要: 自定义错误结构体 package utils type MyError struct { Code int Message string } func NewMyError(code int, msg string) error { return &MyError{Code: code, Messa 阅读全文
posted @ 2019-12-23 14:31 离地最远的星 阅读(379) 评论(0) 推荐(0) 编辑
摘要: 首先放上httptransport.NewServer的源碼 func NewServer( e endpoint.Endpoint, dec DecodeRequestFunc, enc EncodeResponseFunc, options ...ServerOption, //这里的不定长参数可以用来自定义错误处理 ) *Server { s := ... 阅读全文
posted @ 2019-12-23 14:13 离地最远的星 阅读(678) 评论(0) 推荐(0) 编辑