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 #40 from microservices-demo/add-circuitbreaker
Browse files Browse the repository at this point in the history
Add circuitbreaker
  • Loading branch information
pidster authored Jan 20, 2017
2 parents 59fc6e4 + 76247e7 commit ca1adfe
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
21 changes: 11 additions & 10 deletions api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/tracing/opentracing"
httptransport "github.com/go-kit/kit/transport/http"
"github.com/go-kit/kit/circuitbreaker"
"github.com/gorilla/mux"
"github.com/microservices-demo/user/users"
stdopentracing "github.com/opentracing/opentracing-go"
Expand All @@ -37,70 +38,70 @@ func MakeHTTPHandler(ctx context.Context, e Endpoints, logger log.Logger, tracer

r.Methods("GET").Path("/login").Handler(httptransport.NewServer(
ctx,
e.LoginEndpoint,
circuitbreaker.Hystrix("Login")(e.LoginEndpoint),
decodeLoginRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /login", logger)))...,
))
r.Methods("POST").Path("/register").Handler(httptransport.NewServer(
ctx,
e.RegisterEndpoint,
circuitbreaker.Hystrix("Register")(e.RegisterEndpoint),
decodeRegisterRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /register", logger)))...,
))
r.Methods("GET").PathPrefix("/customers").Handler(httptransport.NewServer(
ctx,
e.UserGetEndpoint,
circuitbreaker.Hystrix("UserGet")(e.UserGetEndpoint),
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /customers", logger)))...,
))
r.Methods("GET").PathPrefix("/cards").Handler(httptransport.NewServer(
ctx,
e.CardGetEndpoint,
circuitbreaker.Hystrix("CardGet")(e.CardGetEndpoint),
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /cards", logger)))...,
))
r.Methods("GET").PathPrefix("/addresses").Handler(httptransport.NewServer(
ctx,
e.AddressGetEndpoint,
circuitbreaker.Hystrix("AddressGet")(e.AddressGetEndpoint),
decodeGetRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /addresses", logger)))...,
))
r.Methods("POST").Path("/customers").Handler(httptransport.NewServer(
ctx,
e.UserPostEndpoint,
circuitbreaker.Hystrix("UserPost")(e.UserPostEndpoint),
decodeUserRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /customers", logger)))...,
))
r.Methods("POST").Path("/addresses").Handler(httptransport.NewServer(
ctx,
e.AddressPostEndpoint,
circuitbreaker.Hystrix("AddressPost")(e.AddressPostEndpoint),
decodeAddressRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /addresses", logger)))...,
))
r.Methods("POST").Path("/cards").Handler(httptransport.NewServer(
ctx,
e.CardPostEndpoint,
circuitbreaker.Hystrix("CardPost")(e.CardPostEndpoint),
decodeCardRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "POST /cards", logger)))...,
))
r.Methods("DELETE").PathPrefix("/").Handler(httptransport.NewServer(
ctx,
e.DeleteEndpoint,
circuitbreaker.Hystrix("Delete")(e.DeleteEndpoint),
decodeDeleteRequest,
encodeResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "DELETE /", logger)))...,
))
r.Methods("GET").PathPrefix("/health").Handler(httptransport.NewServer(
ctx,
e.HealthEndpoint,
circuitbreaker.Hystrix("Health")(e.HealthEndpoint),
decodeHealthRequest,
encodeHealthResponse,
append(options, httptransport.ServerBefore(opentracing.FromHTTPRequest(tracer, "GET /health", logger)))...,
Expand Down
32 changes: 23 additions & 9 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import:
- metrics/prometheus
- tracing/opentracing
- transport/http
- circuitbreaker
- package: github.com/gorilla/mux
- package: github.com/opentracing/opentracing-go
- package: github.com/openzipkin/zipkin-go-opentracing
Expand All @@ -22,3 +23,6 @@ import:
subpackages:
- bson
- package: gopkg.in/tomb.v2
- package: github.com/afex/hystrix-go
subpackages:
- hystrix

0 comments on commit ca1adfe

Please sign in to comment.