Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SessionReceiver

Package version

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

Hierarchy

  • SessionReceiver

Index

Accessors

isClosed

  • get isClosed(): boolean

receiveMode

sessionId

  • get sessionId(): string | undefined

sessionLockedUntilUtc

  • get sessionLockedUntilUtc(): Date | undefined
  • property

    The time in UTC until which the session is locked. Everytime renewSessionLock() is called, this time gets updated to current time plus the lock duration as specified during the Queue/Subscription creation.

    Will return undefined until a AMQP receiver link has been successfully set up for the session.

    readonly

    Returns Date | undefined

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 or receiver is closed.

    throws

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

    throws

    MessagingError if the service returns an error while receiving messages.

    Returns AsyncIterableIterator<ServiceBusMessage>

getState

  • getState(): Promise<any>

isReceivingMessages

  • isReceivingMessages(): boolean

peek

  • Fetches the next batch of active messages (including deferred but not deadlettered messages) in the current session.

    • The first call to peek() fetches the first active message. Each subsequent call fetches the subsequent message.
    • Unlike a received message, peeked message is a read-only version of the message. It cannot be Completed/Abandoned/Deferred/Deadlettered. The lock on it cannot be renewed.
    throws

    Error if the underlying connection or receiver is closed.

    throws

    MessagingError if the service returns an error while peeking for messages.

    Parameters

    • Optional maxMessageCount: undefined | number

      The maximum number of messages to peek. Default value 1.

    Returns Promise<ReceivedMessageInfo[]>

    Promise<ReceivedMessageInfo[]>

peekBySequenceNumber

  • peekBySequenceNumber(fromSequenceNumber: Long, maxMessageCount?: undefined | number): Promise<ReceivedMessageInfo[]>
  • Peeks the desired number of active messages (including deferred but not deadlettered messages) from the specified sequence number in the current session.

    • Unlike a received message, peeked message is a read-only version of the message. It cannot be Completed/Abandoned/Deferred/Deadlettered. The lock on it cannot be renewed.
    throws

    Error if the underlying connection or receiver is closed.

    throws

    MessagingError if the service returns an error while peeking for messages.

    Parameters

    • fromSequenceNumber: Long

      The sequence number from where to read the message.

    • Optional maxMessageCount: undefined | number

    Returns Promise<ReceivedMessageInfo[]>

    Promise<ReceivedSBMessage[]>

receiveDeferredMessage

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

    throws

    Error if the underlying connection 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 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 or receiver is closed.

    throws

    Error if the 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 SessionReceiver.

    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 the receiver is already in state of receiving messages.

    throws

    MessagingErrormif 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: SessionMessageHandlerOptions

      Options to control whether messages should be automatically completed or if the lock on the session should be 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

renewSessionLock

  • renewSessionLock(): Promise<Date>
  • Renews the lock on the session for the duration as specified during the Queue/Subscription creation.

    • Check the sessionLockedUntilUtc property on the SessionReceiver for the time when the lock expires.
    • When the lock on the session expires
      • No more messages can be received using this receiver
      • If a message is not settled (using either complete(), defer() or deadletter(), before the session lock expires, then the message lands back in the Queue/Subscription for the next receive operation.
    throws

    Error if the underlying connection or receiver is closed.

    throws

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

    Returns Promise<Date>

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

setState

  • setState(state: any): Promise<void>

Generated using TypeDoc