Options
All
  • Public
  • Public/Protected
  • All
Menu

基于 Redis 的负载均衡客户端。 每个客户端都需要负责接受请求与处理请求。 请求会被转发给负载最低的实例处理。

Type parameters

  • T: any[]

  • U

Hierarchy

  • EventEmitter
    • LoadBalancer

Index

Constructors

constructor

  • Parameters

    • consumer: ILoadBalancerConsumer<T, U>

      负责处理请求的消费者实例,consumer 通过派发 LOAD_CHANGE 事件通知 LoadBalancer 其负载的变化。

    • Optional redisUrl: undefined | string
    • Default value __namedParameters: object = {}
      • poolId: string

        LoadBalancer 资源池的标识,同样 poolId LoadBalancer 之间是隔离的。用于在一个 Redis 中运行多个 LoadBalancer。

      • reportInterval: number

        上报本地 consumer load 时间间隔,单位毫秒。

    Returns LoadBalancer

Properties

Private Optional _online

_online: undefined | false | true

Protected consumer

consumer: ILoadBalancerConsumer<T, U>

负责处理请求的消费者实例,consumer 通过派发 LOAD_CHANGE 事件通知 LoadBalancer 其负载的变化。

id

id: string = generateId(5)

loads

loads: object

Type declaration

  • [key: string]: number

open

open: boolean = true

Private redis

redis: Redis.Redis

Private redisKey

redisKey: string

Private redisPRCNode

redisPRCNode: RedisPRCNode<T, U>

Private redisPrefix

redisPrefix: string

Private reportInterval

reportInterval: number

Private Optional reportIntervalTimer

reportIntervalTimer: NodeJS.Timer

Static defaultMaxListeners

defaultMaxListeners: number

Static errorMonitor

errorMonitor: keyof symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Accessors

online

  • get online(): undefined | false | true
  • set online(value: undefined | false | true): void
  • 标记是否在线。在离线状态下,客户端会直接处理收到的请求。

    Returns undefined | false | true

  • 标记是否在线。在离线状态下,客户端会直接处理收到的请求。

    Parameters

    • value: undefined | false | true

    Returns void

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

close

  • close(): Promise<any>

consume

  • consume(...params: T): Promise<U>

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

Private fetchLoads

  • fetchLoads(): Promise<undefined | object>

Private getLowestLoadInfo

  • getLowestLoadInfo(): Promise<[string, number]>
  • 获取负载最低的实例与其负载

    Returns Promise<[string, number]>

    实例 id 与其负载

getMaxListeners

  • getMaxListeners(): number
  • Returns number

getStatus

  • getStatus(): Promise<object>

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Private reportLoad

  • reportLoad(): Promise<void>

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc