Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Messaging

Hierarchy

  • Messaging

Index

Constructors

constructor

  • new Messaging(_serviceName: string, __namedParameters?: object): Messaging
  • Parameters

    • _serviceName: string
    • Default value __namedParameters: object = {}
      • enableMemoryQos: boolean
      • enableQos: boolean
      • memoryHardLimit: number
      • memorySoftLimit: number
      • qosThreshold: number
      • readyOnConnected: boolean
      • retryStrategy: RetryStrategy

    Returns Messaging

Properties

latencyMS

latencyMS: number

Static defaultConnectionTimeout

defaultConnectionTimeout: number = 30000

Static instances

instances: Messaging[] = []

Static internalExchangePrefix

internalExchangePrefix: string = "internal"

Methods

assertLeader

  • assertLeader(noQueue?: boolean): Promise<string>
  • Parameters

    • Default value noQueue: boolean = false

    Returns Promise<string>

close

  • close(deleteAllQueues?: boolean, force?: boolean): Promise<void>
  • Cleanly closes the connection to Rabbit and removes all handlers. Request queue is not deleted.

    Parameters

    • Default value deleteAllQueues: boolean = false

      Delete queues only if empty and not used.

    • Default value force: boolean = false

      Forces deletion (no check on ifEmpty & ifUnused).

    Returns Promise<void>

    Promise that resolves once the connection has been fully closed.

connect

  • connect(rabbitURI?: string): Promise<void>
  • Parameters

    • Optional rabbitURI: string

    Returns Promise<void>

emit

  • emit<T>(target: string, route: string, messageBody?: T, messageHeaders?: MessageHeaders, __namedParameters?: object): Promise<void>
  • Emit an event to a target. Target can be a service or just a commonly agreed namespace.

    Type parameters

    • T

    Parameters

    • target: string
    • route: string
    • Optional messageBody: T
    • Default value messageHeaders: MessageHeaders = {}
    • Default value __namedParameters: object = {}
      • onlyIfConnected: boolean

    Returns Promise<void>

getEventEmitter

  • getEventEmitter(): EventEmitter

getInternalExchangeName

  • getInternalExchangeName(): string
  • Get the default name used for declaring internal listen queues.

    Returns string

getLastMessageDate

  • getLastMessageDate(): Date
  • Get the last Date object where a message was received. Does not account for internal messages.

    Returns Date

getMaxParallelism

  • getMaxParallelism(): number

getRequestsReport

  • getRequestsReport(serviceName: string, route: string): Promise<RequestReport>
  • Returns a report about the request queue of a target service

    Parameters

    • serviceName: string

      name of the service to get the report about

    • route: string

      name of the route for which the report needs to be generated.

    Returns Promise<RequestReport>

getServiceId

  • getServiceId(): string
  • Get the UUID generated for this instance.

    Returns string

getServiceName

  • getServiceName(): string
  • Returns the name of the service (name supplied while instantiating the service).

    Returns string

getServiceOptions

getStatus

  • getStatus(targetService?: string): Promise<Status>
  • Ask for the status of a service

    Parameters

    • Default value targetService: string = this._serviceName

      the service name for which a status report needs to be generated

    Returns Promise<Status>

getURI

  • getURI(): string
  • Retrieve the URI to which the instance is connected. undefined when not connected yet.

    Returns string

getUptime

handle

isConnected

  • isConnected(): boolean

isReady

  • isReady(): boolean

listen

  • PUB/SUB creates an event listener

    Parameters

    • target: string

      The target on which you want to listen by default it's the serviceName but it can be the name of a commonly agreed exchange

    • route: string

      The route on which to listen

    • listener: MessageHandler

      The callback function that will be called each time a message arrives on that route

    • Optional options: ListenerOptions

    Returns Promise<ReturnHandler>

    resolves when listeners are fully asserted and returns an object which has a "stop" function.

  • PUB/SUB creates an event listener

    Parameters

    • route: string

      The route on which to listen

    • listener: MessageHandler

      The callback function that will be called each time a message arrives on that route

    • Optional options: ListenerOptions

    Returns Promise<ReturnHandler>

    resolves when listeners are fully asserted and returns an object which has a "stop" function.

notify

  • notify(...args: any[]): Promise<void>
  • Like task without ack

    Parameters

    • Rest ...args: any[]

    Returns Promise<void>

on

  • on(event: "leader", listener: function): this
  • on(event: "leader.stepUp", listener: function): this
  • on(event: "leader.stepDown", listener: function): this
  • on(event: "pressure", listener: function): this
  • on(event: "pressureReleased", listener: function): this
  • on(event: "closed", listener: function): this
  • on(event: "connected", listener: function): this
  • on(event: "unhandledMessage", listener: function): this
  • on(event: "error", listener: function): this
  • on(event: "unroutableMessage", listener: function): this
  • on(event: "message.timeout", listener: function): this
  • Raised each time the leader is changing

    Parameters

    • event: "leader"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • The process receiving this message was not the master and became master

    Parameters

    • event: "leader.stepUp"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • The process receiving this message was previously the master process and is not enymore

    Parameters

    • event: "leader.stepDown"
    • listener: function
        • Parameters

          Returns void

    Returns this

  • We detected that the event loop or the memory is becoming unresponsive, if QOS is enabled, messages flowing in will be dramatically reduced

    Parameters

    Returns this

  • The memory or event loop pressure has been released

    Parameters

    Returns this

  • The connection to rabbit has been closed

    Parameters

    • event: "closed"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Conncetion to rabbit successfully established

    Parameters

    • event: "connected"
    • listener: function
        • (): void
        • Returns void

    Returns this

  • Raised when receiving a message for which there is no handler

    Parameters

    • event: "unhandledMessage"
    • listener: function
        • (error: CustomError, message: Message): void
        • Parameters

          • error: CustomError
          • message: Message

          Returns void

    Returns this

  • An error happened

    Parameters

    • event: "error"
    • listener: function
        • (error: CustomError): void
        • Parameters

          • error: CustomError

          Returns void

    Returns this

  • The request or event you sent could not be delivered because the target queue doesn't exists

    Parameters

    • event: "unroutableMessage"
    • listener: function
        • (error: CustomError): void
        • Parameters

          • error: CustomError

          Returns void

    Returns this

  • Get notified of received requests where an answer was expected within a timeout for which no answer was given on time.

    Parameters

    • event: "message.timeout"
    • listener: function
        • (error: CustomError, message: Message): void
        • Parameters

          • error: CustomError
          • message: Message

          Returns void

    Returns this

once

  • once(event: OwnEvents, listener: function): this

reportError

  • reportError(e: Error | CustomError, m?: Message): void

request

  • request<T>(targetService: string, route: string, messageBody?: any, __namedParameters?: object, __namedParameters?: object, streamHandler?: function): Promise<Message<T>>
  • RPC implementation. Request a service identified by the name targetService. The promise will resolve when the target replies or that there is an error (timeout, unroutable, etc.) If there are multiple instances of the targetService, only one will handle it. Use timeout: -1 if you don't want the request to timeout.

    Type parameters

    • T

    Parameters

    • targetService: string

      The name of the service that will have to handle the request

    • route: string

      A routing key to the handler in the targetService

    • Default value messageBody: any = ""

      The message to send

    • Default value __namedParameters: object = {}
    • Default value __namedParameters: object = {}
      • timeout: number

        how long max before giving up on getting an answer to the request

    • Default value streamHandler: function = null

      callback that will be called when the reply is a stream

    Returns Promise<Message<T>>

    The final response message to the request

setMaxParallelism

  • setMaxParallelism(value: number): void

setQosMaxParallelism

  • setQosMaxParallelism(value?: number): Promise<void>
  • Parameters

    • Optional value: number

    Returns Promise<void>

task

  • task(targetService: string, route: string, messageBody?: any, __namedParameters?: object, __namedParameters?: object): Promise<void | Message>
  • Worker queue implementation. By default we always want an acknowledgment to a sent task (for backwards compatibility).

    Parameters

    • targetService: string

      The name of the service that will have to handle the request

    • route: string

      A routing key to the handler in the targetService

    • Default value messageBody: any = ""

      The message to send.

    • Default value __namedParameters: object = {}
    • Default value __namedParameters: object = {}
      • noAck: boolean
      • timeout: number

    Returns Promise<void | Message>

    A promise that resolves once the message has been sent or a proxied request

Static defaultMemoryLimit

  • defaultMemoryLimit(): object

Generated using TypeDoc