Documentation ¶
Index ¶
- Constants
- Variables
- func WithDefaultTimeoutOption(timeout time.Duration) heartHubOption
- func WithDegreeOfParallelismOption(degree int) heartHubOption
- func WithEventBufferSizeOption(bufferSize int) heartHubOption
- func WithHeartbeatBufferSizeOption(bufferSize int) heartHubOption
- func WithLoggerOption(logger Logger) heartHubOption
- func WithSubscribeEventNamesOption(eventNames ...string) heartHubOption
- func WithVerboseInfoOption() heartHubOption
- type DynamicTimeoutHeartHub
- type Event
- type HeartHub
- type Logger
Constants ¶
const ( // EventTimeout event will trigger when a heart meet timeout. EventTimeout = "TIME_OUT" // EventHeartBeat event will be triggered when a heart receives a heartbeat. EventHeartBeat = "HEART_BEAT" // EventRemoveKey event will be triggered when a heartbeat key be removed. EventRemoveKey = "REMOVE_KEY" )
Variables ¶
var ErrDynamicNotSupported error = errors.New("heartbeat: this HeartHub has been closed")
ErrDynamicNotSupported will be return from heartbeatWithTimeout method when the HeartHub do not support dynamic timeout.
var ErrHubClosed error = errors.New("heartbeat: this HeartHub has been closed")
ErrHubClosed will be return from heartbeat method when the HeartHub be closed.
var ErrNoDefaultTimeout error = errors.New("heartbeat: this HeartHub has been closed")
ErrNoDefaultTimeout will be return from heartbeat method when the default timeout do not be set.
Functions ¶
func WithDefaultTimeoutOption ¶ added in v0.9.1
WithDefaultTimeoutOption can set timeout to the hearthub.
func WithDegreeOfParallelismOption ¶
func WithDegreeOfParallelismOption(degree int) heartHubOption
WithDegreeOfParallelismOption can control degree of parallelism.
func WithEventBufferSizeOption ¶
func WithEventBufferSizeOption(bufferSize int) heartHubOption
WithEventBufferSizeOption can set event buffer size.
func WithHeartbeatBufferSizeOption ¶
func WithHeartbeatBufferSizeOption(bufferSize int) heartHubOption
WithHeartbeatBufferSizeOption can set heartbeat buffer size.
func WithLoggerOption ¶
func WithLoggerOption(logger Logger) heartHubOption
WithLoggerOption can set logger to the hearthub.
func WithSubscribeEventNamesOption ¶
func WithSubscribeEventNamesOption(eventNames ...string) heartHubOption
WithSubscribeEventNamesOption can set watch events to hearthub.
func WithVerboseInfoOption ¶
func WithVerboseInfoOption() heartHubOption
WithVerboseInfoOption can set log level.
Types ¶
type DynamicTimeoutHeartHub ¶ added in v0.9.9
type DynamicTimeoutHeartHub interface { HeartHub // Heartbeat will beat the heart of specified key. // This method will auto re-watch the key from heartHub after timeout. // @key: The unique key of target service. // @timeout: The timeout duration after this heartbeat. // @extra: It will be carried back by event data. HeartbeatWithTimeout(key string, timeout time.Duration, extra interface{}) error // Heartbeat will beat the heart of specified key. // This method will auto remove the key from heartHub after timeout. // @key: The unique key of target service. // @timeout: The timeout duration after this heartbeat. // @extra: It will be carried back by event data. DisposableHeartbeatWithTimeout(key string, timeout time.Duration, extra interface{}) error }
DynamicTimeoutHeartHub is a dynamic timeout heartHub.
func NewDynamicTimeoutHeartHub ¶ added in v0.9.9
func NewDynamicTimeoutHeartHub(options ...heartHubOption) DynamicTimeoutHeartHub
NewDynamicTimeoutHeartHub will make a dynamic timeout heartHub.
type Event ¶
type Event struct { EventName string `json:"event_name"` HeartKey string `json:"heart_key"` JoinTime time.Time `json:"join_time"` // JoinTime is register time of the key. EventTime time.Time `json:"event_time"` // Event trigger time. Timeout time.Duration `json:"timeout"` // Timeout duration. TimeoutTime time.Time `json:"beat_time"` Disposable bool `json:"disposable"` Extra interface{} // Extra is the extra data you pass by calling heartbeat method. }
Event just means an event, you can use GetEventChannel method to receive subscribed events.
type HeartHub ¶
type HeartHub interface { // GetEventChannel return a channel for receiving subscribed events. GetEventChannel() <-chan *Event // Heartbeat will beat the heart of specified key. // This method will auto re-watch the key from heartHub after timeout. // @key: The unique key of target service. // @extra: It will be carried back by event data. Heartbeat(key string, extra interface{}) error // Heartbeat will beat the heart of specified key. // This method will auto remove the key from heartHub after timeout. // @key: The unique key of target service. // @extra: It will be carried back by event data. DisposableHeartbeat(key string, extra interface{}) error // Remove will stop watching the service of key from the heartHub. // @key: The unique key of target service. Remove(key string) error // Close will stop watch all service keys and release all goroutines. Close() }
HeartHub is the api entrance of this package.
func NewFixedTimeoutHeartHub ¶ added in v0.9.1
NewFixedTimeoutHeartHub will make a fixed timeout heartHub.