Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Receiver

Package version

The Receiver class can be used to receive messages in a batch or by registering handlers. Use the createReceiver function on the QueueClient or SubscriptionClient to instantiate a Receiver. The Receiver class is an abstraction over the underlying AMQP receiver link.

Hierarchy

  • Receiver

Index

Accessors

isClosed

  • get isClosed(): boolean

receiveMode

Methods

close

  • close(): Promise<void>

getMessageIterator

  • Gets an async iterator over messages from the receiver.

    Throws an error if there is another receive operation in progress on the same receiver. If you are not sure whether there is another receive operation running, check the isReceivingMessages property on the receiver.

    If the iterator is not able to fetch a new message in over a minute, undefined will be returned.

    throws

    Error if the underlying connection, client or receiver is closed.

    throws

    Error if current receiver is already in state of receiving messages.

    throws

    MessagingError if the service returns an error while receiving messages.

    Returns AsyncIterableIterator<ServiceBusMessage>

isReceivingMessages

  • isReceivingMessages(): boolean

receiveDeferredMessage

  • Returns a promise that resolves to a deferred message identified by the given sequenceNumber.

    throws

    Error if the underlying connection, client or receiver is closed.

    throws

    MessagingError if the service returns an error while receiving deferred message.

    Parameters

    • sequenceNumber: Long

      The sequence number of the message that needs to be received.

    Returns Promise<ServiceBusMessage | undefined>

    Promise<ServiceBusMessage | undefined>

    • Returns Message identified by sequence number.
    • Returns undefined if no such message is found.

receiveDeferredMessages

  • Returns a promise that resolves to an array of deferred messages identified by given sequenceNumbers.

    throws

    Error if the underlying connection, client or receiver is closed.

    throws

    MessagingError if the service returns an error while receiving deferred messages.

    Parameters

    • sequenceNumbers: Long[]

      An array of sequence numbers for the messages that need to be received.

    Returns Promise<ServiceBusMessage[]>

    Promise<ServiceBusMessage[]>

    • Returns a list of messages identified by the given sequenceNumbers.
    • Returns an empty list if no messages are found.

receiveMessages

  • receiveMessages(maxMessageCount: number, maxWaitTimeInSeconds?: undefined | number): Promise<ServiceBusMessage[]>
  • Returns a promise that resolves to an array of messages based on given count and timeout over an AMQP receiver link from a Queue/Subscription.

    Throws an error if there is another receive operation in progress on the same receiver. If you are not sure whether there is another receive operation running, check the isReceivingMessages property on the receiver.

    throws

    Error if the underlying connection, client or receiver is closed.

    throws

    Error if current receiver is already in state of receiving messages.

    throws

    MessagingError if the service returns an error while receiving messages.

    Parameters

    • maxMessageCount: number

      The maximum number of messages to receive from Queue/Subscription.

    • Optional maxWaitTimeInSeconds: undefined | number

      The total wait time in seconds until which the receiver will attempt to receive specified number of messages. If this time elapses before the maxMessageCount is reached, then messages collected till then will be returned to the user.

      • Default: 60 seconds.

    Returns Promise<ServiceBusMessage[]>

    Promise<ServiceBusMessage[]> A promise that resolves with an array of Message objects.

registerMessageHandler

  • Registers handlers to deal with the incoming stream of messages over an AMQP receiver link from a Queue/Subscription. To stop receiving messages, call close() on the Receiver.

    Throws an error if there is another receive operation in progress on the same receiver. If you are not sure whether there is another receive operation running, check the isReceivingMessages property on the receiver.

    throws

    Error if the underlying connection or receiver is closed.

    throws

    Error if current receiver is already in state of receiving messages.

    throws

    MessagingError if the service returns an error while receiving messages. These are bubbled up to be handled by user provided onError handler.

    Parameters

    • onMessage: OnMessage

      Handler for processing each incoming message.

    • onError: OnError

      Handler for any error that occurs while receiving or processing messages.

    • Optional options: MessageHandlerOptions

      Options to control if messages should be automatically completed, and/or have their locks automatically renewed. You can control the maximum number of messages that should be concurrently processed. You can also provide a timeout in seconds to denote the amount of time to wait for a new message before closing the receiver.

    Returns void

    void

renewMessageLock

  • Renews the lock on the message for the duration as specified during the Queue/Subscription creation.

    • Check the lockedUntilUtc property on the message for the time when the lock expires.
    • If a message is not settled (using either complete(), defer() or deadletter(), before its lock expires, then the message lands back in the Queue/Subscription for the next receive operation.
    throws

    Error if the underlying connection, client or receiver is closed.

    throws

    MessagingError if the service returns an error while renewing message lock.

    Parameters

    • lockTokenOrMessage: string | ServiceBusMessage

      The lockToken property of the message or the message itself.

    Returns Promise<Date>

    Promise - New lock token expiry date and time in UTC format.

Generated using TypeDoc