Options
All
  • Public
  • Public/Protected
  • All
Menu

Class representing the Rabbit module

Hierarchy

  • Rabbit

Index

Properties

Options that RabbitMQ connection was instantiated with.

pch: Promise<<internal>.Channel>
mgmturl: string
vhost: string
prefix?: string
exchange: string
io: Io
timeout: number = 30000
httpsAgent: <internal>.Agent

Constructors

  • Rabbit constructor.

    This will be automatically called as part of the Io constructor if rabbit is enabled. The following options may be configured for Rabbit, as defined within the cog.json. The default values are shown below:

    {
    "url": "localhost",
    "username": "guest",
    "password": "guest",
    "exchange": "amq.topic",
    "vhost": "/",
    }

    If you wish to enable SSL for communication, you will need to set ssl to true, and then point the following keys at the appropriate file paths:

    • ca
    • cert
    • key

    and optionally define a passphrase for the key file.

    Parameters

    Returns <internal>.Rabbit

Methods

  • setTimeout(timeout: number): void
  • Set the timeout in ms to use for the publishRpc method.

    The default is 3000ms, which should be sufficient for most cases.

    Parameters

    • timeout: number

      The new timeout in ms

    Returns void

  • close(): Promise<void>
  • Close the RabbitMQ connection. The connection is closed automatically when the Io instance is destroyed.

    Returns Promise<void>

  • resolveTopicName(topicName: string): string
  • getContentType(content: unknown): string
  • publishTopic(topic: string, content?: unknown, options?: <internal>.Publish): Promise<boolean>
  • Publish a message to a RabbitMQ topic.

    This method allows for passing content to the specified topic. The content can be a string, number, object, or buffer, and in the case of the first three, will be implicitly converted to a buffer before sending to RabbitMQ. In these cases, the content type will be automatically determined based on type and set as follows:

    • Buffer - application/octet-stream
    • number - text/number
    • string - text/string
    • object - application/json

    If you wish to override the content type, you can pass options.contentType to the method.

    Parameters

    • topic: string

      The routing key for the message.

    • content: unknown = ...

      The message to publish. If left blank, will default to an empty buffer.

    • options: <internal>.Publish = {}

      Publishing options. See amqplib#publish for details on options.

    Returns Promise<boolean>

  • Subscribe to a RabbitMQ topic.

    For each method that is recieved for a topic, the callback will be called with the RabbitMQ message. On receiving the message, the content property will be automatically converted to an appropriate type based on the content type of the message. The content type to be used can be overriden by setting the options.contentType field. You should only need to set the content type if interfacing with the legacy @cisl/io package.

    Type Parameters

    • T = unknown

      The expected type of the content is in the message. If not specified, defaults to string | numer | object | Buffer.

    Parameters

    Returns Promise<<internal>.Consume>

  • Subscribe to a RabbitMQ topic.

    For each method that is recieved for a topic, the callback will be called with the RabbitMQ message. On receiving the message, the content property will be automatically converted to an appropriate type based on the content type of the message. The content type to be used can be overriden by setting the options.contentType field. You should only need to set the content type if interfacing with the legacy @cisl/io package.

    Type Parameters

    • T = unknown

      The expected type of the content is in the message. If not specified, defaults to string | numer | object | Buffer.

    Parameters

    Returns Promise<<internal>.Consume>

  • The promise returned by this method is resolved when the response is received from the callee. The response will be automatically parsed to the appropriate type based on the content type. You can override this behavior by setting options.contentType. You may leave both content and options blank.

    Type Parameters

    • T = unknown

      The type of the content of the response. Defaults to string | number | object | Buffer.

    Parameters

    • queueName: string

      The name of the queue to use for the RPC.

    • content: unknown = ...

      The content to send to the callee. If left blank, will default to an empty buffer.

    • options: <internal>.Publish = {}

      The options to use.

    Returns Promise<<internal>.RabbitMessage<T>>

  • When a message is received on the given queue, the handler will be called with the message. The content of the message is automatically parsed to the appropriate type based on the content type. You can override this behavior by setting the options.contentType setting.

    Type Parameters

    • T

      The type of the content of the response. Defaults to string | number | object | Buffer.

    Parameters

    Returns Promise<void>

  • When a message is received on the given queue, the handler will be called with the message. The content of the message is automatically parsed to the appropriate type based on the content type. You can override this behavior by setting the options.contentType setting.

    Type Parameters

    • T

      The type of the content of the response. Defaults to string | number | object | Buffer.

    Parameters

    Returns Promise<void>

  • Listen to a RabbitMQ queue.

    When a message is received on the given queue, the handler will be called with the message. The content of the message is automatically parsed to the appropriate type based on the content type. You can override this behavior by setting the options.contentType setting.

    The full allowed properties for options can be viwed at amqplib#assertQueue.

    Parameters

    Returns Promise<void>

  • Listen to a RabbitMQ queue.

    When a message is received on the given queue, the handler will be called with the message. The content of the message is automatically parsed to the appropriate type based on the content type. You can override this behavior by setting the options.contentType setting.

    The full allowed properties for options can be viwed at amqplib#assertQueue.

    Parameters

    Returns Promise<void>

Generated using TypeDoc