Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #30 from microservices-demo/add_circuitbreaker
Browse files Browse the repository at this point in the history
Add circuitbreaker
  • Loading branch information
pidster committed Jan 20, 2017
2 parents 321d412 + 0011592 commit 6d8a459
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
28 changes: 23 additions & 5 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (
"net/http"
"strconv"
"strings"
"time"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/tracing/opentracing"
"github.com/go-kit/kit/circuitbreaker"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
stdopentracing "github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sony/gobreaker"
"golang.org/x/net/context"
)

Expand All @@ -34,28 +37,40 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, imagePath string, logger

r.Methods("GET").Path("/catalogue").Handler(httptransport.NewServer(
ctx,
e.ListEndpoint,
circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
Name: "List",
Timeout: 30 * time.Second,
}))(e.ListEndpoint),
decodeListRequest,
encodeListResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /catalogue", logger)))...,
))
r.Methods("GET").Path("/catalogue/size").Handler(httptransport.NewServer(
ctx,
e.CountEndpoint,
circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
Name: "Count",
Timeout: 30 * time.Second,
}))(e.CountEndpoint),
decodeCountRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /catalogue/size", logger)))...,
))
r.Methods("GET").Path("/catalogue/{id}").Handler(httptransport.NewServer(
ctx,
e.GetEndpoint,
circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
Name: "Get",
Timeout: 30 * time.Second,
}))(e.GetEndpoint),
decodeGetRequest,
encodeGetResponse, // special case, this one can have an error
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /catalogue/{id}", logger)))...,
))
r.Methods("GET").Path("/tags").Handler(httptransport.NewServer(
ctx,
e.TagsEndpoint,
circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
Name: "Tags",
Timeout: 30 * time.Second,
}))(e.TagsEndpoint),
decodeTagsRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /tags", logger)))...,
Expand All @@ -66,7 +81,10 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, imagePath string, logger
))
r.Methods("GET").PathPrefix("/health").Handler(httptransport.NewServer(
ctx,
e.HealthEndpoint,
circuitbreaker.Gobreaker(gobreaker.NewCircuitBreaker(gobreaker.Settings{
Name: "Health",
Timeout: 30 * time.Second,
}))(e.HealthEndpoint),
decodeHealthRequest,
encodeHealthResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /health", logger)))...,
Expand Down
37 changes: 36 additions & 1 deletion vendor/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"branch": "master",
"notests": true
},
{
"importpath": "github.com/afex/hystrix-go/hystrix",
"repository": "https://github.com/afex/hystrix-go",
"vcs": "git",
"revision": "39520ddd07a9d9a071d615f7476798659f5a3b89",
"branch": "master",
"path": "/hystrix",
"notests": true
},
{
"importpath": "github.com/apache/thrift/lib/go/thrift",
"repository": "https://github.com/apache/thrift",
Expand Down Expand Up @@ -85,6 +94,15 @@
"branch": "master",
"notests": true
},
{
"importpath": "github.com/go-kit/kit/circuitbreaker",
"repository": "https://github.com/go-kit/kit",
"vcs": "git",
"revision": "b8f878dd8851dd7b724c813f04d469fa2dae881a",
"branch": "master",
"path": "/circuitbreaker",
"notests": true
},
{
"importpath": "github.com/go-kit/kit/endpoint",
"repository": "https://github.com/go-kit/kit",
Expand Down Expand Up @@ -435,6 +453,14 @@
"branch": "master",
"notests": true
},
{
"importpath": "github.com/sony/gobreaker",
"repository": "https://github.com/sony/gobreaker",
"vcs": "git",
"revision": "809bcd5a528f344e95c2368796c9225d128f9b3e",
"branch": "master",
"notests": true
},
{
"importpath": "github.com/stathat/go",
"repository": "https://github.com/stathat/go",
Expand All @@ -443,6 +469,15 @@
"branch": "master",
"notests": true
},
{
"importpath": "github.com/streadway/handy/breaker",
"repository": "https://github.com/streadway/handy",
"vcs": "git",
"revision": "f450267a206e480d863d2a92846a40f6e2896b2a",
"branch": "master",
"path": "/breaker",
"notests": true
},
{
"importpath": "github.com/stretchr/testify/assert",
"repository": "https://github.com/stretchr/testify",
Expand Down Expand Up @@ -536,4 +571,4 @@
"notests": true
}
]
}
}

0 comments on commit 6d8a459

Please sign in to comment.