Documentation
¶
Index ¶
- type HystrixGoPlugin
- func (p *HystrixGoPlugin) Disable(b bool)
- func (p *HystrixGoPlugin) Exec(async bool, ...) (interface{}, error)
- func (p *HystrixGoPlugin) ExecWithContext(async bool, ctx context.Context, ...) (interface{}, error)
- func (p *HystrixGoPlugin) Reset()
- func (p *HystrixGoPlugin) Update(timeout int, maxConcurrentRequests int, requestVolumeThreshold int, ...) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HystrixGoPlugin ¶
type HystrixGoPlugin struct {
HystrixGo *hystrixgo.CircuitBreaker
// contains filtered or unexported fields
}
HystrixGoPlugin each instance represents a specific command circuit breaker is tracking against multiple commands use a map to track all commands and invoke circuit breaker per command
HystrixGo must not be set to nil or swapped after initialization unless the plugin is discarded and not currently in service. Methods are concurrency-safe, but best practice is one plugin per command lifecycle.
func NewHystrixGoPlugin ¶
func NewHystrixGoPlugin(commandName string, timeout int, maxConcurrentRequests int, requestVolumeThreshold int, sleepWindow int, errorPercentThreshold int, logger *data.ZapLog) (*HystrixGoPlugin, error)
NewHystrixGoPlugin creates a hystrixgo plugin struct object this plugin implements the CircuitBreakerIFace interface
Config Properties:
- commandName = (required) name of the circuit breaker command
- Timeout = (optional) how long to wait for command to complete, in milliseconds, default = 1000
- MaxConcurrentRequests = (optional) how many commands of the same type can run at the same time, default = 10
- RequestVolumeThreshold = (optional) minimum number of requests needed before a circuit can be tripped due to health, default = 20
- SleepWindow = (optional) how long to wait after a circuit opens before testing for recovery, in milliseconds, default = 5000
- ErrorPercentThreshold = (optional) causes circuits to open once the rolling measure of errors exceeds this percent of requests, default = 50
- Logger = (optional) indicates the logger that will be used in the Hystrix package, nil = logs nothing
func (*HystrixGoPlugin) Disable ¶
func (p *HystrixGoPlugin) Disable(b bool)
Disable will disable circuit breaker services true = disable; false = re-engage circuit breaker service
func (*HystrixGoPlugin) Exec ¶
func (p *HystrixGoPlugin) Exec(async bool, runFn func(dataIn interface{}, ctx ...context.Context) (dataOut interface{}, err error), fallbackFn func(dataIn interface{}, errIn error, ctx ...context.Context) (dataOut interface{}, err error), dataIn interface{}) (interface{}, error)
Exec offers both async and sync execution of circuit breaker action Note: fallbackFn may be nil if no fallback logic is required
runFn = function to be executed under circuit breaker fallbackFn = function to be executed if runFn fails (can be nil) dataIn = input parameter value for runFn and fallbackFn
func (*HystrixGoPlugin) ExecWithContext ¶
func (p *HystrixGoPlugin) ExecWithContext(async bool, ctx context.Context, runFn func(dataIn interface{}, ctx ...context.Context) (dataOut interface{}, err error), fallbackFn func(dataIn interface{}, errIn error, ctx ...context.Context) (dataOut interface{}, err error), dataIn interface{}) (interface{}, error)
ExecWithContext offers both async and sync execution of circuit breaker action with context Note: fallbackFn may be nil if no fallback logic is required
runFn = function to be executed under circuit breaker fallbackFn = function to be executed if runFn fails dataIn = input parameter value for runFn and fallbackFn
func (*HystrixGoPlugin) Reset ¶
func (p *HystrixGoPlugin) Reset()
Reset will cause circuit breaker to reset all circuits from memory
func (*HystrixGoPlugin) Update ¶
func (p *HystrixGoPlugin) Update(timeout int, maxConcurrentRequests int, requestVolumeThreshold int, sleepWindow int, errorPercentThreshold int, logger *data.ZapLog) error
Update will update circuit breaker internal config
- Timeout = (optional) how long to wait for command to complete, in milliseconds, default = 1000
- MaxConcurrentRequests = (optional) how many commands of the same type can run at the same time, default = 10
- RequestVolumeThreshold = (optional) minimum number of requests needed before a circuit can be tripped due to health, default = 20
- SleepWindow = (optional) how long to wait after a circuit opens before testing for recovery, in milliseconds, default = 5000
- ErrorPercentThreshold = (optional) causes circuits to open once the rolling measure of errors exceeds this percent of requests, default = 50
- Logger = (optional) indicates the logger that will be used in the Hystrix package, nil = logs nothing