Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MessageEnvelope

Allows adding additional information to messages. A correlation id, message id, and a message type are added to the data being sent/received. Additionally, a MessageEnvelope can reference a lock token.

Side note: a MessageEnvelope's message is stored as a buffer, so strings are converted using utf8 conversions.

Hierarchy

  • MessageEnvelope

Index

Constructors

constructor

  • new MessageEnvelope(correlationId: string, messageType: string, message: any): MessageEnvelope
  • Creates a new MessageEnvelope, which adds a correlation id, message id, and a type to the data being sent/received.

    Parameters

    • correlationId: string

      (optional) transaction id to trace execution through call chain.

    • messageType: string

      a string value that defines the message's type.

    • message: any

      the data being sent/received.

    Returns MessageEnvelope

Properties

correlation_id

correlation_id: string

The unique business transaction id that is used to trace calls across components.

message

message: Buffer

The stored message.

message_id

message_id: string

The message's auto-generated ID.

message_type

message_type: string

String value that defines the stored message's type.

sent_time

sent_time: Date

The time at which the message was sent.

Methods

getMessageAs

  • getMessageAs<T>(): T
  • Type parameters

    • T

    Returns T

    the value that was stored in this message as a JSON string.

getMessageAsJson

  • getMessageAsJson(): any
  • Returns any

    the value that was stored in this message as a JSON string.

getMessageAsString

  • getMessageAsString(): string
  • Returns string

    the information stored in this message as a UTF-8 encoded string.

getReference

  • getReference(): any
  • Returns any

    the lock token that this MessageEnvelope references.

setMessageAsJson

  • setMessageAsJson(value: any): void
  • Stores the given value as a JSON string.

    see

    getMessageAsJson

    Parameters

    • value: any

      the value to convert to JSON and store in this message.

    Returns void

setMessageAsObject

  • setMessageAsObject(value: any): void
  • Stores the given value as a object.

    see

    getMessageAsJson

    Parameters

    • value: any

      the value to convert to JSON and store in this message.

    Returns void

setMessageAsString

  • setMessageAsString(value: string): void
  • Stores the given string.

    Parameters

    • value: string

      the string to set. Will be converted to a buffer, using UTF-8 encoding.

    Returns void

setReference

  • setReference(value: any): void
  • Sets a lock token reference for this MessageEnvelope.

    Parameters

    • value: any

      the lock token to reference.

    Returns void

toJSON

  • toJSON(): any
  • Converts this MessageEnvelop to a JSON string. The message payload is passed as base64 string

    Returns any

    A JSON encoded representation is this object.

toString

  • toString(): string
  • Convert's this MessageEnvelope to a string, using the following format:

    "[<correlation_id>,<message_type>,<message.toString>]".

    If any of the values are null, they will be replaced with ---.

    Returns string

    the generated string.

Static fromJSON

  • Converts a JSON string into a MessageEnvelop The message payload is passed as base64 string

    Parameters

    • value: string

      a JSON encoded string

    Returns MessageEnvelope

    a decoded Message Envelop.

Generated using TypeDoc