Skip to content

Commit ef52f28

Browse files
author
irahardianto
committed
update readme
1 parent e9e9c1d commit ef52f28

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,10 @@ Essentially circuit breaker works just like electrical circuit breakers, nothing
435435

436436
In our case, we will be using hystrix-go, it is a go port from Netflix's hystrix library, how it works is essentially the same, even hystrix-go supports turbine along with its hystrix dashboard, but in my case, I rather use the datadog plugins, since we are using datadog to monitor our system.
437437

438-
For the sake of SOLID principles implementation in our codebase, we will add hystrix-go to our PlayerRepository leveraging decorator pattern, this will maintain our base repository implementation, the one that calls database, clean from modification and we will create its extension which is named PlayerRepositoryWithCircuitBreaker. If you recall we inject our PlayerService with PlayerRepositoryWithCircuitBreaker and the original PlayerRepository wrapped inside.
438+
For the sake of SOLID principles implementation in our codebase, we will add hystrix-go to our PlayerRepository leveraging decorator pattern, this will maintain our base repository implementation, the one that calls database, clean from modification and we will create its extension which is named PlayerRepositoryWithCircuitBreaker. This is the O part of SOLID which stands for Open for extension, Close for modification.
439+
440+
441+
If you recall we inject our PlayerService with PlayerRepositoryWithCircuitBreaker and the original PlayerRepository wrapped inside.
439442

440443
playerService.PlayerRepository = &repositories.PlayerRepositoryWithCircuitBreaker{playerRepository}
441444

@@ -483,6 +486,13 @@ PlayerRepository extension implementation :
483486
}
484487
}
485488

489+
Basically PlayerRepositoryWithCircuitBreaker implement the same interface as PlayerRepository, IPlayerRepository
490+
491+
type IPlayerRepository interface {
492+
GetPlayerByName(name string) (models.PlayerModel, error)
493+
}
494+
495+
486496
As you see here, it is very easy to implement hystrix-go circuit breaker, you just need to wrap your db call inside hystrix if the timeout reached, the circuit breaker will be tripped and all calls to database will be halt, error will be returned instead for future call until db service is up and healthy.
487497

488498

0 commit comments

Comments
 (0)