plugins

package
v1.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HystrixGoPlugin

type HystrixGoPlugin struct {
	HystrixGo *hystrixgo.CircuitBreaker
}

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

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:

  1. commandName = (required) name of the circuit breaker command
  2. Timeout = (optional) how long to wait for command to complete, in milliseconds, default = 1000
  3. MaxConcurrentRequests = (optional) how many commands of the same type can run at the same time, default = 10
  4. RequestVolumeThreshold = (optional) minimum number of requests needed before a circuit can be tripped due to health, default = 20
  5. SleepWindow = (optional) how long to wait after a circuit opens before testing for recovery, in milliseconds, default = 5000
  6. ErrorPercentThreshold = (optional) causes circuits to open once the rolling measure of errors exceeds this percent of requests, default = 50
  7. 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

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) 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

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

  1. Timeout = (optional) how long to wait for command to complete, in milliseconds, default = 1000
  2. MaxConcurrentRequests = (optional) how many commands of the same type can run at the same time, default = 10
  3. RequestVolumeThreshold = (optional) minimum number of requests needed before a circuit can be tripped due to health, default = 20
  4. SleepWindow = (optional) how long to wait after a circuit opens before testing for recovery, in milliseconds, default = 5000
  5. ErrorPercentThreshold = (optional) causes circuits to open once the rolling measure of errors exceeds this percent of requests, default = 50
  6. Logger = (optional) indicates the logger that will be used in the Hystrix package, nil = logs nothing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL