Options
All
  • Public
  • Public/Protected
  • All
Menu

pinus-rpc

Index

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

Type aliases

MailBoxFactory

MailBoxFactory: function

Type declaration

MailBoxTimeoutCallback

MailBoxTimeoutCallback: function

Type declaration

    • (tracer: Tracer, err: Error, resp?: any): void
    • Parameters

      • tracer: Tracer
      • err: Error
      • Optional resp: any

      Returns void

MailStationErrorHandler

MailStationErrorHandler: function

Type declaration

    • (err: Error, serverId: string, msg: any, opts: any): void
    • Parameters

      • err: Error
      • serverId: string
      • msg: any
      • opts: any

      Returns void

Proxies

Proxies: object

Type declaration

  • [namespace: string]: object
    • [serverType: string]: object
      • [attr: string]: Function

ProxyCallback

ProxyCallback: function

Type declaration

    • (serviceName: string, methodName: string, args: any[], attach: any, isToSpecifiedServer?: boolean): Promise<any>
    • Parameters

      • serviceName: string
      • methodName: string
      • args: any[]
      • attach: any
      • Optional isToSpecifiedServer: boolean

      Returns Promise<any>

RemoteMethod

RemoteMethod: function

Type declaration

    • (...args: any[]): Promise<any>
    • Parameters

      • Rest ...args: any[]

      Returns Promise<any>

Remoter

Remoter: object

Type declaration

Remoters

Remoters: object

Type declaration

Router

Router: defRoute | object

RpcFilter

RpcFilterFunction

RpcFilterFunction: function

Type declaration

    • (serverId: string, msg: any, opts: any, next: function): void
    • Parameters

      • serverId: string
      • msg: any
      • opts: any
      • next: function
          • (target?: Error | string, message?: any, options?: any): void
          • Parameters

            • Optional target: Error | string
            • Optional message: any
            • Optional options: any

            Returns void

      Returns void

Services

Services: object

Type declaration

Variables

BUFFER_SIZE_DEFAULT

BUFFER_SIZE_DEFAULT: number = 32

CONNECT_TIMEOUT

CONNECT_TIMEOUT: number = 2000

Composer

Composer: any = require('stream-pkg')

DEFAULT_CALLBACK_TIMEOUT

DEFAULT_CALLBACK_TIMEOUT: number = 10 * 1000

DEFAULT_INTERVAL

DEFAULT_INTERVAL: number = 50

DEFAULT_ZIP_LENGTH

DEFAULT_ZIP_LENGTH: number = 1024 * 10

KEEP_ALIVE_INTERVAL

KEEP_ALIVE_INTERVAL: number = 30 * 1000

KEEP_ALIVE_TIMEOUT

KEEP_ALIVE_TIMEOUT: number = 10 * 1000

MqttCon

MqttCon: any = require('mqtt-connection')

STATE_CLOSED

STATE_CLOSED: number = 3

STATE_INITED

STATE_INITED: number = 1

Client states

STATE_STARTED

STATE_STARTED: number = 2

ch

ch: chRoute = chRoute

checkArray

checkArray: (Anonymous function) = Array.isArray || isType("Array")

Utils check array

param
returns

true|false

api

public

checkBoolean

checkBoolean: (Anonymous function) = isType("Boolean")

Utils check boolean

param

object

returns

true|false

api

public

checkFunction

checkFunction: (Anonymous function) = isType("Function")

Utils check function

param

function

returns

true|false

api

public

checkNumber

checkNumber: (Anonymous function) = isType("Number")

Utils check number

param
returns

true|false

api

public

checkObject

checkObject: (Anonymous function) = isType("Object")

Utils check object

param

object

returns

true|false

api

public

checkString

checkString: (Anonymous function) = isType("String")

Utils check string

param
returns

true|false

api

public

curId

curId: number = 1

df

df: defRoute = defRoute

la

la: laRoute = laRoute

logger

logger: Logger = getLogger('pinus-rpc', 'ws-acceptor')

rd

rd: rdRoute = rdRoute

rr

rr: rrRoute = rrRoute

typeArray

typeArray: string[] = ['', 'null', 'buffer', 'array', 'string', 'object', 'bean', 'boolean', 'float', 'number']

typeMap

typeMap: any

useZipCompress

useZipCompress: boolean = false

wrr

wrr: wrrRoute = wrrRoute

Functions

addToPending

  • addToPending(tracer: Tracer, station: object, serverId: string, args: IArguments): void

applyCallback

  • applyCallback(cb: Function, args: any[]): void

chRoute

  • chRoute(client: RpcClient, serverType: string, msg: RpcMsg, cb: function): void
  • Consistent-Hash algorithm for calculating server id.

    Parameters

    • client: RpcClient

      rpc client.

    • serverType: string

      rpc target serverType.

    • msg: RpcMsg

      rpc message.

    • cb: function

      cb(err, serverId).

        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

checkBean

  • checkBean(obj: any): boolean
  • Utils check bean

    Parameters

    • obj: any

      object

    Returns boolean

    true|false

checkFloat

  • checkFloat(v: any): boolean
  • Utils check float

    api

    public

    Parameters

    • v: any

    Returns boolean

    true|false

checkNull

  • checkNull(obj: any): boolean

compare

  • compare(v1: string, v2: string): number

create

  • Factory method to create mailbox

    Parameters

    • server: object

      remote server info {id:"", host:"", port:""}

      • host: string
      • id: string
      • port: number
    • opts: MailBoxOpts

      construct parameters opts.origin {Object} delegated object opts.proxyCB {Function} proxy invoke callback opts.service {String} deletgated service name opts.attach {Object} attach parameter pass to proxyCB

    Returns MailBox

    proxy instance

createAcceptor

createClient

  • RPC client factory method.

    Parameters

    • opts: RpcClientOpts

      client init parameter. opts.context: mail box init parameter, opts.router: (optional) rpc message route function, route(routeParam, msg, cb), opts.mailBoxFactory: (optional) mail box factory instance.

    Returns RpcClient

    client instance.

createGateway

createMailBox

  • default mailbox factory

    Parameters

    • serverInfo: object

      single server instance info, {id, host, port, ...}

      • host: string
      • id: string
      • port: number
    • opts: MailBoxOpts

      construct parameters

    Returns MailBox

    mailbox instancef

createMailStation

  • Mail station factory function.

    Parameters

    • Optional opts: MailStationOpts

      construct paramters opts.servers {Object} global server info map. {serverType: [{id, host, port, ...}, ...]} opts.mailboxFactory {Function} mailbox factory function

    • Optional mailboxFactory: MailBoxFactory

    Returns MailStation

    mail station instance

createNamespace

  • createNamespace(namespace: string, proxies: object): void
  • createNamespace(namespace: string, proxies: Services): void

createServer

  • Create rpc server.

    Parameters

    • opts: RpcServerOpts

      construct parameters opts.port {Number|String} rpc server listen port opts.paths {Array} remote service code paths, [{namespace, path}, ...] opts.context {Object} context for remote service opts.acceptorFactory {Object} (optionals)acceptorFactory(opts, cb)

    Returns Gateway

    rpc server instance

createStation

decodeClient

  • decodeClient(buf: Buffer): object
  • Parameters

    • buf: Buffer

    Returns object

    • id: number
    • resp: string | object | (string | object)[]

decodeServer

  • decodeServer(buf: Buffer, servicesMap: object): object
  • Parameters

    • buf: Buffer
    • servicesMap: object
      • [key: number]: any

    Returns object

    • id: number
    • msg: object
      • args: string | object | (string | object)[]
      • method: any
      • namespace: any
      • service: any

defRoute

  • defRoute(session: object, msg: RpcMsg, context: object, cb: function): void
  • Calculate route info and return an appropriate server id.

    Parameters

    • session: object

      session object for current rpc request

      • [key: string]: any
    • msg: RpcMsg

      rpc message. {serverType, service, method, args, opts}

    • context: object

      context of client

      • [key: string]: any
    • cb: function
        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

doFilter

  • doFilter(tracer: Tracer, err: Error, serverId: string, msg: MailBoxMessage, opts: object, filters: Array<RpcFilter>, index: number, operate: "before" | "after", cb: Function): void

encodeClient

  • encodeClient(id: number, msg: Msg, servicesMap: object): Buffer
  • Parameters

    • id: number
    • msg: Msg
    • servicesMap: object
      • [key: number]: any

    Returns Buffer

encodeServer

  • encodeServer(id: number, args: object): Buffer

errorHandler

  • errorHandler(tracer: Tracer, station: MailStation, err: Error, serverId: string, msg: object, opts: object, flag: boolean, cb: Function): void

failback

  • failback(code: number, tracer: object, serverId: string, msg: object, opts: object, cb: Function): void
  • Failback rpc failure process. This will try the same server with sendInterval option and retries option.

    Parameters

    • code: number

      error code number.

    • tracer: object

      current rpc tracer.

      • [key: string]: any
    • serverId: string

      rpc remote target server id.

    • msg: object

      rpc message.

      • serverType: string
    • opts: object

      rpc client options.

      • [key: string]: any
    • cb: Function

      user rpc callback.

    Returns void

failfast

  • failfast(code: number, tracer: object, serverId: string, msg: object, opts: object, cb: Function): void
  • Failfast rpc failure process. This will ignore error in rpc client.

    Parameters

    • code: number

      error code number.

    • tracer: object

      current rpc tracer.

      • [key: string]: any
    • serverId: string

      rpc remote target server id.

    • msg: object

      rpc message.

      • serverType: string
    • opts: object

      rpc client options.

      • [key: string]: any
    • cb: Function

      user rpc callback.

    Returns void

failover

  • failover(this: any, code: number, tracer: object, serverId: string, msg: object, opts: object, cb: Function): void
  • Failover rpc failure process. This will try other servers with option retries.

    Parameters

    • this: any
    • code: number

      error code number.

    • tracer: object

      current rpc tracer.

      • servers: object
    • serverId: string

      rpc remote target server id.

    • msg: object

      rpc message.

      • serverType: string
    • opts: object

      rpc client options.

    • cb: Function

      user rpc callback.

    Returns void

failsafe

  • failsafe(this: any, code: number, tracer: object, serverId: string, msg: object, opts: object, cb: Function): void
  • Failsafe rpc failure process.

    Parameters

    • this: any
    • code: number

      error code number.

    • tracer: object

      current rpc tracer.

      • [key: string]: any
    • serverId: string

      rpc remote target server id.

    • msg: object

      rpc message.

      • serverType: string
    • opts: object

      rpc client options.

      • [key: string]: any
    • cb: Function

      user rpc callback.

    Returns void

failureProcess

  • failureProcess(this: any, code: string, tracer: any, serverId: string, msg: object, opts: object): void
  • Parameters

    • this: any
    • code: string
    • tracer: any
    • serverId: string
    • msg: object
    • opts: object
      • failMode: string

    Returns void

flushPending

  • flushPending(tracer: Tracer, station: object, serverId: string, cb?: Function): void

genFunctionProxy

  • genFunctionProxy(serviceName: string, methodName: string, origin: any, attach: boolean, proxyCB: ProxyCallback): Proxy
  • Generate prxoy for function type field

    Parameters

    • serviceName: string

      delegated service name

    • methodName: string

      delegated method name

    • origin: any

      origin object

    • attach: boolean
    • proxyCB: ProxyCallback

      proxy callback function

    Returns Proxy

    function proxy

genObjectProxy

  • genObjectProxy(serviceName: string, origin: any, attach: any, proxyCB: ProxyCallback): object

generateProxy

  • Generate proxies for remote servers.

    Parameters

    • client: RpcClient

      current client instance.

    • record: RemoteServerCode

      proxy reocrd info. {namespace, serverType, path}

    • context: object

      mailbox init context parameter

    Returns object

    • [key: string]: any

getBearcat

  • getBearcat(): any

getKeysLength

  • getKeysLength<T>(map: object): number

getModule

  • getModule(module: string): string

getObjectClass

  • getObjectClass(obj: Object): string

getRouteTarget

  • getRouteTarget(client: RpcClient, serverType: string, msg: RpcMsg, routeParam: object, cb: function): void
  • Calculate remote target server id for rpc client.

    Parameters

    • client: RpcClient

      current client instance.

    • serverType: string

      remote server type.

    • msg: RpcMsg
    • routeParam: object

      mailbox init context parameter.

    • cb: function

      return rpc remote target server id.

        • (err: Error, serverId: string): void
        • Parameters

          • err: Error
          • serverId: string

          Returns void

    Returns void

getType

  • getType(object: any): any

hash

  • hash(algorithm: string, str: string): string

insertProxy

  • insertProxy(proxies: Proxies, namespace: string, serverType: string, proxy: object): void
  • Add proxy into array.

    Parameters

    • proxies: Proxies

      rpc proxies

    • namespace: string

      rpc namespace sys/user

    • serverType: string

      rpc remote server type

    • proxy: object

      rpc proxy

      • [key: string]: any

    Returns void

invokeCallback

  • invokeCallback(cb: Function, err: Error): void
  • Parameters

    • cb: Function
    • err: Error

    Returns void

isNotNull

  • isNotNull(value: any): boolean
  • Utils check is not null

    Parameters

    • value: any

    Returns boolean

    true|false

isType

  • isType(type: any): (Anonymous function)
  • Utils check type

    api

    public

    Parameters

    • type: any

    Returns (Anonymous function)

    high order function

laRoute

  • laRoute(client: RpcClient & object, serverType: string, msg: RpcMsg, cb: function): void
  • Least-Active algorithm for calculating server id.

    Parameters

    • client: RpcClient & object

      rpc client.

    • serverType: string

      rpc target serverType.

    • msg: RpcMsg

      rpc message.

    • cb: function

      cb(err, serverId).

        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

lazyConnect

  • lazyConnect(tracer: Tracer, station: object, serverId: string, factory: MailBoxFactory, cb: Function): boolean

listEs6ClassMethods

  • listEs6ClassMethods(objInstance: object): string[]
  • 列出ES6的一个Class实例上的所有方法,但不包括父类的

    Parameters

    • objInstance: object
      • [key: string]: any

    Returns string[]

loadRemoteServices

proxyCB

  • proxyCB(client: RpcClient, serviceName: string, methodName: string, args: Array<any>, attach: object, isToSpecifiedServer: boolean): Promise<Object>
  • Generate prxoy for function type field

    Parameters

    • client: RpcClient

      current client instance.

    • serviceName: string

      delegated service name.

    • methodName: string

      delegated method name.

    • args: Array<any>

      rpc invoke arguments.

    • attach: object

      attach parameter pass to proxyCB.

      • [key: string]: any
    • isToSpecifiedServer: boolean

      true means rpc route to specified remote server.

    Returns Promise<Object>

rdRoute

  • rdRoute(client: RpcClient, serverType: string, msg: RpcMsg, cb: function): void
  • Random algorithm for calculating server id.

    Parameters

    • client: RpcClient

      rpc client.

    • serverType: string

      rpc target serverType.

    • msg: RpcMsg

      rpc message.

    • cb: function

      cb(err, serverId).

        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

rpcToSpecifiedServer

  • rpcToSpecifiedServer(client: RpcClient, msg: RpcMsg, serverType: string, serverId: string, cb: ErrorCallback<__type>): void
  • Rpc to specified server id or servers.

    Parameters

    • client: RpcClient

      current client instance.

    • msg: RpcMsg

      rpc message.

    • serverType: string

      remote server type.

    • serverId: string

      mailbox init context parameter.

    • cb: ErrorCallback<__type>

    Returns void

rrRoute

  • rrRoute(client: RpcClient & object, serverType: string, msg: RpcMsg, cb: function): void
  • Round-Robin algorithm for calculating server id.

    Parameters

    • client: RpcClient & object

      rpc client.

    • serverType: string

      rpc target serverType.

    • msg: RpcMsg

      rpc message.

    • cb: function

      cb(err, serverId).

        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

to_array

  • to_array(args: any[]): any[]
  • Utils args to array

    Parameters

    • args: any[]

      arguments

    Returns any[]

    array

wrrRoute

  • wrrRoute(client: RpcClient, serverType: string, msg: RpcMsg, cb: function): void
  • Weight-Round-Robin algorithm for calculating server id.

    Parameters

    • client: RpcClient

      rpc client.

    • serverType: string

      rpc target serverType.

    • msg: RpcMsg

      rpc message.

    • cb: function

      cb(err, serverId).

        • (err: Error, serverId?: string): void
        • Parameters

          • err: Error
          • Optional serverId: string

          Returns void

    Returns void

Object literals

constants

constants: object

TOPIC_HANDSHAKE

TOPIC_HANDSHAKE: string = "h"

TOPIC_RPC

TOPIC_RPC: string = "r"

DEFAULT_PARAM

DEFAULT_PARAM: object

CALLBACK_TIMEOUT

CALLBACK_TIMEOUT: number = 30 * 1000

DEFAULT_PENDING_SIZE

DEFAULT_PENDING_SIZE: number = 10000

FAILSAFE_CONNECT_TIME

FAILSAFE_CONNECT_TIME: number = 5 * 1000

FAILSAFE_RETRIES

FAILSAFE_RETRIES: number = 3

GRACE_TIMEOUT

GRACE_TIMEOUT: number = 3 * 1000

INTERVAL

INTERVAL: number = 50

KEEPALIVE

KEEPALIVE: number = 10 * 1000

FAIL_MODE

FAIL_MODE: object

FAILBACK

FAILBACK: string = "failback"

FAILFAST

FAILFAST: string = "failfast"

FAILOVER

FAILOVER: string = "failover"

FAILSAFE

FAILSAFE: string = "failsafe"

RPC_ERROR

RPC_ERROR: object

FAIL_CONNECT_SERVER

FAIL_CONNECT_SERVER: number = 3

FAIL_FIND_MAILBOX

FAIL_FIND_MAILBOX: number = 4

FAIL_SEND_MESSAGE

FAIL_SEND_MESSAGE: number = 5

FILTER_ERROR

FILTER_ERROR: number = 6

NO_TRAGET_SERVER

NO_TRAGET_SERVER: number = 2

SERVER_NOT_STARTED

SERVER_NOT_STARTED: number = 1

SCHEDULE

SCHEDULE: object

CONSISTENT_HASH

CONSISTENT_HASH: string = "ch"

LEAST_ACTIVE

LEAST_ACTIVE: string = "la"

ROUNDROBIN

ROUNDROBIN: string = "rr"

WEIGHT_ROUNDROBIN

WEIGHT_ROUNDROBIN: string = "wrr"