ServiceBusClient class
A client that can create Sender instances for sending messages to queues and topics as well as Receiver instances to receive messages from queues and subscriptions.
Constructors
Service |
Creates an instance of the ServiceBusClient class which can be used to create senders and receivers to the Azure Service Bus namespace provided in the connection string. No connection is made to the service until the senders/receivers created with the client are used to send/receive messages. |
Service |
Creates an instance of the ServiceBusClient class which can be used to create senders and receivers to the Azure Service Bus namespace provided. No connection is made to the service until the senders/receivers created with the client are used to send/receive messages. |
Properties
fully |
The fully qualified namespace of the Service Bus instance for which this client is created. This is likely to be similar to .servicebus.windows.net. |
identifier | The name used to identify this ServiceBusClient. If not specified or empty, a random unique one will be generated. |
Methods
accept |
Creates a receiver for the next available session in a session-enabled Azure Service Bus queue. You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
accept |
Creates a receiver for the next available session in a session-enabled Azure Service Bus subscription. You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
accept |
Creates a receiver for a session enabled Azure Service Bus queue. You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
accept |
Creates a receiver for a session enabled Azure Service Bus subscription. You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
close() | Closes the underlying AMQP connection. NOTE: this will also disconnect any Receiver or Sender instances created from this instance. |
create |
Creates a receiver for an Azure Service Bus queue. No connection is made to the service until one of the methods on the receiver is called. To target sub queues like the dead letter queue or the transfer dead letter queue, provide the
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
Messages that are not settled within the lock duration will be redelivered as many times as the max delivery count set on the queue, after which they get sent to a separate dead letter queue. You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
create |
Creates a receiver for an Azure Service Bus subscription. No connection is made to the service until one of the methods on the receiver is called. To target sub queues like the dead letter queue or the transfer dead letter queue, provide the
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
Messages that are not settled within the lock duration will be redelivered as many times as the max delivery count set on the subscription, after which they get sent to a separate dead letter queue. You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver. More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock |
create |
Creates an instance of ServiceBusRuleManager that is used to manage the rules for a subscription. |
create |
Creates a Sender which can be used to send messages, schedule messages to be sent at a later time and cancel such scheduled messages. No connection is made to the service until one of the methods on the sender is called. |
Constructor Details
ServiceBusClient(string, ServiceBusClientOptions)
Creates an instance of the ServiceBusClient class which can be used to create senders and receivers to the Azure Service Bus namespace provided in the connection string. No connection is made to the service until the senders/receivers created with the client are used to send/receive messages.
new ServiceBusClient(connectionString: string, options?: ServiceBusClientOptions)
Parameters
- connectionString
-
string
A connection string for Azure Service Bus namespace. NOTE: this connection string can contain an EntityPath, which is ignored.
- options
- ServiceBusClientOptions
Options for the service bus client.
ServiceBusClient(string, TokenCredential | NamedKeyCredential | SASCredential, ServiceBusClientOptions)
Creates an instance of the ServiceBusClient class which can be used to create senders and receivers to the Azure Service Bus namespace provided. No connection is made to the service until the senders/receivers created with the client are used to send/receive messages.
new ServiceBusClient(fullyQualifiedNamespace: string, credential: TokenCredential | NamedKeyCredential | SASCredential, options?: ServiceBusClientOptions)
Parameters
- fullyQualifiedNamespace
-
string
The full namespace of your Service Bus instance which is likely to be similar to .servicebus.windows.net.
- credential
A credential object used by the client to get the token to authenticate the connection
with the Azure Service Bus. See @azure/identity for creating the credentials.
If you're using an own implementation of the TokenCredential
interface against AAD, then set the "scopes" for service-bus
to be ["https://servicebus.azure.net//user_impersonation"]
to get the appropriate token.
Use the AzureNamedKeyCredential
from @azure/core-auth if you want to pass in a SharedAccessKeyName
and SharedAccessKey
without using a connection string. These fields map to the name
and key
field respectively
in AzureNamedKeyCredential
.
Use the AzureSASCredential
from @azure/core-auth if you want to pass in a SharedAccessSignature
without using a connection string. This field maps to signature
in AzureSASCredential
.
- options
- ServiceBusClientOptions
A set of options to apply when configuring the client.
retryOptions
: Configures the retry policy for all the operations on the client. For example,{ "maxRetries": 4 }
or{ "maxRetries": 4, "retryDelayInMs": 30000 }
.webSocketOptions
: Configures the channelling of the AMQP connection over Web Sockets.
Property Details
fullyQualifiedNamespace
The fully qualified namespace of the Service Bus instance for which this client is created. This is likely to be similar to .servicebus.windows.net.
fullyQualifiedNamespace: string
Property Value
string
identifier
The name used to identify this ServiceBusClient. If not specified or empty, a random unique one will be generated.
identifier: string
Property Value
string
Method Details
acceptNextSession(string, ServiceBusSessionReceiverOptions)
Creates a receiver for the next available session in a session-enabled Azure Service Bus queue.
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function acceptNextSession(queueName: string, options?: ServiceBusSessionReceiverOptions): Promise<ServiceBusSessionReceiver>
Parameters
- queueName
-
string
The name of the queue to receive from.
- options
- ServiceBusSessionReceiverOptions
Options include receiveMode(defaulted to peekLock), options to create session receiver.
Returns
Promise<ServiceBusSessionReceiver>
A receiver that can be used to receive, peek and settle messages.
acceptNextSession(string, string, ServiceBusSessionReceiverOptions)
Creates a receiver for the next available session in a session-enabled Azure Service Bus subscription.
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function acceptNextSession(topicName: string, subscriptionName: string, options?: ServiceBusSessionReceiverOptions): Promise<ServiceBusSessionReceiver>
Parameters
- topicName
-
string
Name of the topic for the subscription we want to receive from.
- subscriptionName
-
string
Name of the subscription (under the topic
) that we want to receive from.
- options
- ServiceBusSessionReceiverOptions
Options include receiveMode(defaulted to peekLock), options to create session receiver.
Returns
Promise<ServiceBusSessionReceiver>
A receiver that can be used to receive, peek and settle messages.
acceptSession(string, string, ServiceBusSessionReceiverOptions)
Creates a receiver for a session enabled Azure Service Bus queue.
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function acceptSession(queueName: string, sessionId: string, options?: ServiceBusSessionReceiverOptions): Promise<ServiceBusSessionReceiver>
Parameters
- queueName
-
string
The name of the queue to receive from.
- sessionId
-
string
The id of the session from which messages need to be received
- options
- ServiceBusSessionReceiverOptions
Options include receiveMode(defaulted to peekLock), options to create session receiver.
Returns
Promise<ServiceBusSessionReceiver>
A receiver that can be used to receive, peek and settle messages.
acceptSession(string, string, string, ServiceBusSessionReceiverOptions)
Creates a receiver for a session enabled Azure Service Bus subscription.
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function acceptSession(topicName: string, subscriptionName: string, sessionId: string, options?: ServiceBusSessionReceiverOptions): Promise<ServiceBusSessionReceiver>
Parameters
- topicName
-
string
Name of the topic for the subscription we want to receive from.
- subscriptionName
-
string
Name of the subscription (under the topic
) that we want to receive from.
- sessionId
-
string
The id of the session from which messages need to be received
- options
- ServiceBusSessionReceiverOptions
Options include receiveMode(defaulted to peekLock), options to create session receiver.
Returns
Promise<ServiceBusSessionReceiver>
A receiver that can be used to receive, peek and settle messages.
close()
Closes the underlying AMQP connection. NOTE: this will also disconnect any Receiver or Sender instances created from this instance.
function close(): Promise<void>
Returns
Promise<void>
createReceiver(string, ServiceBusReceiverOptions)
Creates a receiver for an Azure Service Bus queue. No connection is made to the service until one of the methods on the receiver is called.
To target sub queues like the dead letter queue or the transfer dead letter queue, provide the
subQueue
in the options. To learn more about dead letter queues, see
https://docs.microsoft.com/azure/service-bus-messaging/service-bus-dead-letter-queues
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
Messages that are not settled within the lock duration will be redelivered as many times as the max delivery count set on the queue, after which they get sent to a separate dead letter queue.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function createReceiver(queueName: string, options?: ServiceBusReceiverOptions): ServiceBusReceiver
Parameters
- queueName
-
string
The name of the queue to receive from.
- options
- ServiceBusReceiverOptions
Options to pass the receiveMode, defaulted to peekLock.
Returns
A receiver that can be used to receive, peek and settle messages.
createReceiver(string, string, ServiceBusReceiverOptions)
Creates a receiver for an Azure Service Bus subscription. No connection is made to the service until one of the methods on the receiver is called.
To target sub queues like the dead letter queue or the transfer dead letter queue, provide the
subQueue
in the options. To learn more about dead letter queues, see
https://docs.microsoft.com/azure/service-bus-messaging/service-bus-dead-letter-queues
You can choose between two receive modes: "peekLock" (default) and "receiveAndDelete".
- In peekLock mode, the receiver has a lock on the message for the duration specified on the queue.
- In receiveAndDelete mode, messages are deleted from Service Bus as they are received.
Messages that are not settled within the lock duration will be redelivered as many times as the max delivery count set on the subscription, after which they get sent to a separate dead letter queue.
You can settle a message by calling completeMessage(), abandonMessage(), deferMessage() or deadletterMessage() methods on the receiver.
More information about how peekLock and message settlement works here: https://docs.microsoft.com/azure/service-bus-messaging/message-transfers-locks-settlement#peeklock
function createReceiver(topicName: string, subscriptionName: string, options?: ServiceBusReceiverOptions): ServiceBusReceiver
Parameters
- topicName
-
string
Name of the topic for the subscription we want to receive from.
- subscriptionName
-
string
Name of the subscription (under the topic
) that we want to receive from.
- options
- ServiceBusReceiverOptions
Options to pass the receiveMode, defaulted to peekLock.
Returns
A receiver that can be used to receive, peek and settle messages.
createRuleManager(string, string)
Creates an instance of ServiceBusRuleManager that is used to manage the rules for a subscription.
function createRuleManager(topicName: string, subscriptionName: string): ServiceBusRuleManager
Parameters
- topicName
-
string
the topic to create ServiceBusRuleManager
- subscriptionName
-
string
the subscription specific to the specified topic to create a ServiceBusRuleManager for.
Returns
a ServiceBusRuleManager scoped to the specified subscription and topic.
createSender(string, ServiceBusSenderOptions)
Creates a Sender which can be used to send messages, schedule messages to be sent at a later time and cancel such scheduled messages. No connection is made to the service until one of the methods on the sender is called.
function createSender(queueOrTopicName: string, options?: ServiceBusSenderOptions): ServiceBusSender
Parameters
- queueOrTopicName
-
string
The name of a queue or topic to send messages to.
- options
- ServiceBusSenderOptions