Represents an AMQP Channel. Almost all actions in AMQP are performed on a Channel.

Constructors

  • Parameters

    • connection: AMQPBaseClient

      The connection this channel belongs to

    • id: number

      ID of the channel

    Returns AMQPChannel

Properties

closed: boolean = false
confirmId: number = 0
connection: AMQPBaseClient
consumers: Map<string, AMQPConsumer> = ...
delivery?: AMQPMessage
getMessage?: AMQPMessage
id: number
onerror: (reason: string) => void
returned?: AMQPMessage

Methods

  • Acknowledge a delivered message

    Parameters

    • deliveryTag: number

      tag of the message

    • Optionalmultiple: boolean = false

      batch confirm all messages up to this delivery tag

    Returns Promise<void>

  • Consume from a queue. Messages will be delivered asynchronously.

    Parameters

    • queue: string

      name of the queue to poll

    • param: { args?: {}; exclusive?: boolean; noAck?: boolean; tag?: string } = {}
      • Optionalargs?: {}

        custom arguments

      • Optionalexclusive?: boolean

        if this can be the only consumer of the queue, will return an Error if there are other consumers to the queue already

      • OptionalnoAck?: boolean

        if messages are removed from the server upon delivery, or have to be acknowledged

      • Optionaltag?: string

        tag of the consumer, will be server generated if left empty

    • callback: (msg: AMQPMessage) => void

      will be called for each message delivered to this consumer

    Returns Promise<AMQPConsumer>

  • Enable or disable flow. Disabling flow will stop the server from delivering messages to consumers. Not supported in RabbitMQ

    Parameters

    • active: boolean = true

      false to stop the flow, true to accept messages

    Returns Promise<boolean>

  • Synchronously receive a message from a queue

    Parameters

    • queue: string

      name of the queue to poll

    • param: { noAck?: boolean } = {}
      • OptionalnoAck?: boolean

        if message is removed from the server upon delivery, or have to be acknowledged

    Returns Promise<null | AMQPMessage>

    • returns null if the queue is empty otherwise a single message
  • Acknowledge a delivered message

    Parameters

    • deliveryTag: number

      tag of the message

    • Optionalrequeue: boolean = false

      if the message should be requeued or removed

    • Optionalmultiple: boolean = false

      batch confirm all messages up to this delivery tag

    Returns Promise<void>

  • Publish a message

    Parameters

    • exchange: string

      the exchange to publish to, the exchange must exists

    • routingKey: string

      routing key

    • data:
          | null
          | string
          | ArrayBuffer
          | Uint8Array<ArrayBufferLike>
          | Buffer<ArrayBufferLike>

      the data to be published, can be a string or an uint8array

    • properties: AMQPProperties = {}

      properties to be published

    • Optionalmandatory: boolean = false

      if the message should be returned if there's no queue to be delivered to

    • Optionalimmediate: boolean = false

      if the message should be returned if it can't be delivered to a consumer immediately (not supported in RabbitMQ)

    Returns Promise<number>

    • fulfilled when the message is enqueue on the socket, or if publish confirm is enabled when the message is confirmed by the server
  • Set prefetch limit. Recommended to set as each unacknowledged message will be stored in memory of the client. The server won't deliver more messages than the limit until messages are acknowledged.

    Parameters

    • prefetchCount: number

      number of messages to limit to

    • prefetchSize: number = 0

      number of bytes to limit to (not supported by RabbitMQ)

    • global: boolean = false

      if the prefetch is limited to the channel, or if false to each consumer

    Returns Promise<void>

  • Tell the server to redeliver all unacknowledged messages again, or reject and requeue them.

    Parameters

    • Optionalrequeue: boolean = false

      if the message should be requeued or redeliviered to this channel

    Returns Promise<void>

  • Acknowledge a delivered message

    Parameters

    • deliveryTag: number

      tag of the message

    • Optionalrequeue: boolean = false

      if the message should be requeued or removed

    Returns Promise<void>

  • Close the channel gracefully

    Parameters

    • Optionalreason: string = ""

      might be logged by the server

    • code: number = 200

    Returns Promise<void>

  • Enable publish confirm. The server will then confirm each publish with an Ack or Nack when the message is enqueued.

    Returns Promise<void>

  • Exchange to exchange binding.

    Parameters

    • destination: string

      name of the destination exchange

    • source: string

      name of the source exchange

    • routingKey: string = ""

      key to bind with

    • args: {} = {}

      optional arguments, e.g. for header exchanges

    Returns Promise<void>

    fulfilled when confirmed by the server

  • Declare an exchange

    Parameters

    • name: string

      name of the exchange

    • type: string

      type of exchange (direct, fanout, topic, header, or a custom type)

    • param: ExchangeParams = ...
      • OptionalautoDelete?: boolean

        if the exchange should be deleted when the last binding from it is deleted

      • Optionaldurable?: boolean

        if the exchange should survive server restarts

      • Optionalinternal?: boolean

        if exchange is internal to the server. Client's can't publish to internal exchanges.

      • Optionalpassive?: boolean

        if the exchange name doesn't exist the channel will be closed with an error, fulfilled if the exchange name does exists

    • args: {} = {}

      optional arguments

    Returns Promise<void>

    Fulfilled when the exchange is created or if it already exists

  • Delete an exchange

    Parameters

    • name: string

      name of the exchange

    • param: { ifUnused?: boolean } = {}
      • OptionalifUnused?: boolean

        only delete if the exchange doesn't have any bindings

    Returns Promise<void>

    Fulfilled when the exchange is deleted or if it's already deleted

  • Delete an exchange-to-exchange binding

    Parameters

    • destination: string

      name of destination exchange

    • source: string

      name of the source exchange

    • routingKey: string = ""

      key that was bound

    • args: {} = {}

      arguments, e.g. for header exchanges

    Returns Promise<void>

    fulfilled when confirmed by the server

  • Alias for basicQos

    Parameters

    • prefetchCount: number

      max inflight messages

    Returns Promise<void>

  • Bind a queue to an exchange

    Parameters

    • queue: string

      name of the queue

    • exchange: string

      name of the exchange

    • routingKey: string

      key to bind with

    • args: {} = {}

      optional arguments, e.g. for header exchanges

    Returns Promise<void>

    fulfilled when confirmed by the server

  • Declare a queue

    Parameters

    • name: string = ""

      name of the queue, if empty the server will generate a name

    • params: QueueParams = ...
      • OptionalautoDelete?: boolean

        if the queue should be deleted when the last consumer of the queue disconnects

      • Optionaldurable?: boolean

        if the queue should survive server restarts

      • Optionalexclusive?: boolean

        if the queue should be deleted when the channel is closed

      • Optionalpassive?: boolean

        if the queue name doesn't exist the channel will be closed with an error, fulfilled if the queue name does exists

    • args: {} = {}

      optional custom queue arguments

    Returns Promise<QueueOk>

    fulfilled when confirmed by the server

  • Delete a queue

    Parameters

    • name: string = ""

      name of the queue, if empty it will delete the last declared queue

    • params: { ifEmpty?: boolean; ifUnused?: boolean } = {}
      • OptionalifEmpty?: boolean

        only delete if the queue is empty

      • OptionalifUnused?: boolean

        only delete if the queue doesn't have any consumers

    Returns Promise<MessageCount>

  • Unbind a queue from an exchange

    Parameters

    • queue: string

      name of the queue

    • exchange: string

      name of the exchange

    • routingKey: string

      key that was bound

    • args: {} = {}

      arguments, e.g. for header exchanges

    Returns Promise<void>

    fulfilled when confirmed by the server

  • Set this channel in Transaction mode. Rember to commit the transaction, overwise the server will eventually run out of memory.

    Returns Promise<void>