Azure Service Bus client library samples for JavaScript
These sample programs show how to use the JavaScript client libraries for Azure Service Bus in some common scenarios.
File Name | Description |
---|---|
sendMessages.js | Demonstrates how to send messages to Service Bus Queue/Topic |
topicSubscriptionWithRuleOperationsSample.js | Demonstrates how to filter messages in Service Bus |
receiveMessagesLoop.js | Demonstrates how to receive Service Bus messages in a loop |
receiveMessagesStreaming.js | Demonstrates how to receive Service Bus messages in a stream |
usingNamedKeyCredential.js | This sample demonstrates how to authenticate using AzureNamedKeyCredential |
browseMessages.js | Demonstrates how to browse a Service Bus message |
deleteMessages.js | Demonstrates deleting messages from a queue. |
session.js | Demonstrates how to send/receive messages to/from session enabled queues/subscriptions in Service Bus |
scheduledMessages.js | Demonstrates how to schedule messages to appear on a Service Bus Queue/Subscription at a later time |
useProxy.js | This sample demonstrates how to create a ServiceBusClient meant to be used in an environment where outgoing network requests have to go through a proxy server |
advanced/administrationClient.js | Demonstrates how to manage the resources of a service bus namespace. |
advanced/ruleManager.js | Demonstrates how to manage subscription-level rules using RuleManager. |
advanced/sessionRoundRobin.js | Demonstrates how to continually read through all the available sessions |
advanced/deferral.js | Demonstrates how to defer a message for later processing. |
advanced/listingEntities.js | Demonstrates how the ServiceBusAdministrationClient can be used to list the entities of a service bus namespace |
advanced/sessionState.js | Demonstrates usage of SessionState. |
advanced/movingMessagesToDLQ.js | Demonstrates scenarios as to how a Service Bus message can be explicitly moved to the DLQ |
advanced/processMessageFromDLQ.js | Demonstrates retrieving a message from a dead letter queue, editing it and sending it back to the main queue |
exceedMaxDeliveryCount.js | Demonstrates exceeding the max delivery count, then processing the messages sent to the dead letter queue |
Prerequisites
The sample programs are compatible with LTS versions of Node.js.
You need an Azure subscription and the following Azure resources to run these sample programs:
Samples retrieve credentials to access the service endpoint from environment variables. Alternatively, edit the source code to include the appropriate credentials. See each individual sample for details on which environment variables/credentials it requires to function.
Adapting the samples to run in the browser may require some additional consideration. For details, please see the package README.
Setup
To run the samples using the published version of the package:
- Install the dependencies using
npm
:
npm install
Edit the file
sample.env
, adding the correct credentials to access the Azure service and run the samples. Then rename the file fromsample.env
to just.env
. The sample programs will read this file automatically.Run whichever samples you like (note that some samples may require additional setup, see the table above):
node sendMessages.js
Alternatively, run a single sample with the correct environment variables set (setting up the .env
file is not required if you do this), for example (cross-platform):
npx dev-tool run vendored cross-env SERVICEBUS_FQDN="<servicebus fqdn>" QUEUE_NAME="<queue name>" node sendMessages.js
Next Steps
Take a look at our API Documentation for more information about the APIs that are available in the clients.