Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SubscriptionClient

Package version

Describes the client that allows interacting with a Service Bus Subscription. Use the createSubscriptionClient function on the ServiceBusClient object to instantiate a SubscriptionClient

Hierarchy

  • SubscriptionClient

Implements

Index

Properties

defaultRuleName

defaultRuleName: string = "$Default"
readonly
property

The name of the default rule on the subscription.

entityPath

entityPath: string
readonly
property

The path for the Service Bus Subscription for which this client is created.

id

id: string
readonly
property

A unique identifier for this client.

subscriptionName

subscriptionName: string
readonly
property

The name of the Service Bus Subscription for which this client is created.

topicName

topicName: string
readonly
property

The name of the Service Bus Topic for whose Subscription, this client is created.

Methods

addRule

  • addRule(ruleName: string, filter: boolean | string | CorrelationFilter, sqlRuleActionExpression?: undefined | string): Promise<void>
  • Adds a rule on the subscription as defined by the given rule name, filter and action.

    Note: Remove the default true filter on the subscription before adding a rule. Otherwise, the added rule will have no affect as the true filter will always result in the subscription receiving all messages.

    throws

    Error if the SubscriptionClient or the underlying connection is closed.

    throws

    MessagingError if the service returns an error while adding rules.

    Parameters

    • ruleName: string

      Name of the rule

    • filter: boolean | string | CorrelationFilter

      A Boolean, SQL expression or a Correlation filter. For SQL Filter syntax, see SQLFilter syntax.

    • Optional sqlRuleActionExpression: undefined | string

      Action to perform if the message satisfies the filtering expression. For SQL Rule Action syntax, see SQLRuleAction syntax.

    Returns Promise<void>

close

  • close(): Promise<void>

createReceiver

  • Creates a Receiver for receiving messages from a Subscription which does not have sessions enabled.

    throws

    Error if the SubscriptionClient or the underlying connection is closed.

    throws

    Error if an open receiver already exists on the SubscriptionClient.

    throws

    MessagingError with name InvalidOperationError if the Queue has sessions enabled (in which case, use the overload of this method which takes sessionOptions argument)

    Parameters

    • receiveMode: ReceiveMode

      An enum indicating the mode in which messages should be received. Possible values are:

      • ReceiveMode.peekLock: Once a message is received in this mode, the receiver has a lock on the message for a particular duration. If the message is not settled by this time, it lands back on Service Bus to be fetched by the next receive operation.
      • ReceiveMode.receiveAndDelete: Messages received in this mode get automatically removed from Service Bus.

    Returns Receiver

    Receiver A receiver to receive messages from a Subscription which does not have sessions enabled.

  • Creates a Receiver for receiving messages from a session enabled Subscription. When no sessionId is given, a random session among the available sessions is used.

    throws

    Error if the SubscriptionClient or the underlying connection is closed.

    throws

    Error if an open receiver already exists on the SubscriptionClient for given sessionId.

    throws

    MessagingError with name SessionCannotBeLockedError if the Queue does not have sessions enabled (in which case do not pass the sessionOptions argument) or if Service Bus is not able to get a lock on the session (in which case try again after some time)

    Parameters

    • receiveMode: ReceiveMode

      An enum indicating the mode in which messages should be received. Possible values are:

      • ReceiveMode.peekLock: Once a message is received in this mode, the receiver has a lock on the message for a particular duration. If the message is not settled by this time, it lands back on Service Bus to be fetched by the next receive operation.
      • ReceiveMode.receiveAndDelete: Messages received in this mode get automatically removed from Service Bus.
    • sessionOptions: SessionReceiverOptions

      Options to provide sessionId and duration of automatic lock renewal for the session receiver.

    Returns SessionReceiver

    SessionReceiver A receiver to receive from a session in the Subscription.

getRules

peek

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

    • 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 SubscriptionClient or the underlying connection is closed.

    throws

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

    Parameters

    • Optional maxMessageCount: undefined | number

    Returns Promise<ReceivedMessageInfo[]>

    Promise<ReceivedSBMessage[]>

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.

    • 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 SubscriptionClient or the underlying connection 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[]>

removeRule

  • removeRule(ruleName: string): Promise<void>
  • Removes the rule on the subscription identified by the given rule name.

    Caution: If all rules on a subscription are removed, then the subscription will not receive any more messages.

    throws

    Error if the SubscriptionClient or the underlying connection is closed.

    throws

    MessagingError if the service returns an error while removing rules.

    Parameters

    • ruleName: string

    Returns Promise<void>

Generated using TypeDoc