Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • Bus

Index

Constructors

  • new Bus(url: string | Connect, serviceName: string): Bus
  • Creates a new bus client. You can call connect explicitly or call any other method and the connection will be established implicitly.

    Parameters

    • url: string | Connect

      The url of the bus

    • serviceName: string

      The name which groups together instances of services. When using the pub-sub pattern only one instance of a service will receive the published message.

    Returns Bus

Properties

channel?: Channel

The connected channel.

connection?: Connection

The bus connection.

replyQueueEventEmitter: EventEmitter

The event emitter that fires events with a message's correlationId when they are received by the channels direct reply-to pseudo-queue.

serviceName: string

The key which groups together instances of services. When using the pub-sub pattern only one instance of a service will receive the published message.

url: string | Connect

The amqp url.

Methods

  • answer<ReqMsg, ResMsg>(queue: string, onMessage: (msg: ReqMsg) => Promise<ResMsg>, options?: AnswerOptions): Promise<void>
  • Receives and responds to remote procedure calls.

    The default options don't persistently store the messages on the bus and don't guarantee that a service will receive, process or answer the call successfully. Meaning, if a message is received twice, the client must have sent the message twice using call.

    Type parameters

    • ReqMsg = string

      Type of the request message

    • ResMsg = string

      Type of the response message

    Parameters

    • queue: string

      The queue to read messages from

    • onMessage: (msg: ReqMsg) => Promise<ResMsg>

      The callback that gets called every time a new message is received

        • (msg: ReqMsg): Promise<ResMsg>
        • Parameters

          • msg: ReqMsg

          Returns Promise<ResMsg>

    • options: AnswerOptions = {}

      The options used for receiving messages

    Returns Promise<void>

  • call<ReqMsg, ResMsg>(queue: string, msg: ReqMsg, options?: CallOptions): Promise<ResMsg>
  • Sends remote procedure calls and returns the answer synchronously.

    The default options don't persistently store the messages on the bus and don't guarantee that a service will receive, process or answer the call successfully. Check if the call has been processed by checking the return value.

    Type parameters

    • ReqMsg = string

      Type of the request message

    • ResMsg = string

      Type of the response message

    Parameters

    • queue: string

      The queue to write messages to

    • msg: ReqMsg

      The message itself. Will be serialized using stringify.

    • options: CallOptions = {}

      The options used for sending messages

    Returns Promise<ResMsg>

    A promise of the response message

  • close(): Promise<void>
  • connect(): Promise<void>
  • Creates a connection with the bus using the url supplied during initialization.

    Returns Promise<void>

  • getConnectedChannel(): Promise<Channel>
  • Gets the current connected channel. If there is none it calls connect to create a channel.

    throws

    {@link Error} This exception is thrown if the channel isn't ready after connect has been called.

    Returns Promise<Channel>

    The connected channel

  • publish<Msg>(routingKey: string, msg: Msg, options?: PublishOptions): Promise<void>
  • Publishes a message with a routing key.

    The default options guarantee that all published messages will be stored on the bus until one instance of each service has processed the message.

    Type parameters

    • Msg = string

      Type of the message

    Parameters

    • routingKey: string

      The amqp routing key used for the message

    • msg: Msg

      The message itself. Will be serialized using stringify.

    • options: PublishOptions = ...

      The options used for sending the message

    Returns Promise<void>

  • stringify(value: any): string
  • Stringifies any input using JSON.

    Parameters

    • value: any

      The input to stringify

    Returns string

    The JSON string

  • subscribe<Msg>(routingKey: string, onMessage: (msg: Msg, routingKey: string) => Promise<void>, options?: SubscribeOptions): Promise<void>
  • Subscribes to a routing key and calls onMessage on every message.

    The default options guarantee that all published messages will be stored persistently on the bus until one instance of each service has processed the message. All instances of the same running service should have the same serviceName, which is supplied during initialization.

    Type parameters

    • Msg = string

      Type of a received message

    Parameters

    • routingKey: string

      The amqp routing key used for the messages that should be received

    • onMessage: (msg: Msg, routingKey: string) => Promise<void>

      The callback that gets called every time a new message is received by this instance. See Error handling for information about acknowledgments and redeliveries.

        • (msg: Msg, routingKey: string): Promise<void>
        • Parameters

          • msg: Msg
          • routingKey: string

          Returns Promise<void>

    • options: SubscribeOptions = ...

      The options used for receiving messages

    Returns Promise<void>

Generated using TypeDoc