You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-bus-messaging/service-bus-nodejs-how-to-use-queues.md
+91-85Lines changed: 91 additions & 85 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,53 +1,57 @@
1
1
---
2
-
title: Get started with Azure Service Bus queues (JavaScript)
2
+
title: 'Quickstart: Get started with Azure Service Bus queues (JavaScript)'
3
3
description: This tutorial shows you how to send messages to and receive messages from Azure Service Bus queues using the JavaScript programming language.
4
4
author: spelluru
5
5
ms.author: spelluru
6
-
ms.date: 12/08/2023
6
+
ms.date: 06/13/2025
7
7
ms.topic: quickstart
8
8
ms.devlang: javascript
9
9
ms.custom: devx-track-js, mode-api
10
+
#customer intent: As a developer, I want to learn how to send and receive messages with Azure Service Bus queues by using the Python programming language.
10
11
---
11
12
12
-
# Send messages to and receive messages from Azure Service Bus queues (JavaScript)
13
+
# Quickstart: Send messages to and receive messages from Azure Service Bus queues (JavaScript)
13
14
> [!div class="op_single_selector" title1="Select the programming language:"]
In this tutorial, you complete the following steps:
20
+
This quickstart provides step-by-step instructions for a simple scenario of sending messages to a Service Bus queue and receiving them. In this quickstart, you complete the following tasks:
20
21
21
-
1. Create a Service Bus namespace, using the Azure portal.
22
-
2. Create a Service Bus queue, using the Azure portal.
23
-
3. Write a JavaScript application to use the [@azure/service-bus](https://www.npmjs.com/package/@azure/service-bus) package to:
24
-
1. Send a set of messages to the queue.
25
-
1. Receive those messages from the queue.
22
+
- Create a Service Bus namespace, using the Azure portal.
23
+
- Create a Service Bus queue, using the Azure portal.
24
+
- Write a JavaScript application to use the [@azure/service-bus](https://www.npmjs.com/package/@azure/service-bus) package to:
25
+
26
+
- Send a set of messages to the queue.
27
+
- Receive those messages from the queue.
26
28
27
-
> [!NOTE]
28
-
> This quick start provides step-by-step instructions for a simple scenario of sending messages to a Service Bus queue and receiving them. You can find pre-built JavaScript and TypeScript samples for Azure Service Bus in the [Azure SDK for JavaScript repository on GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/samples/v7).
29
+
You can find prebuilt JavaScript and TypeScript samples for Azure Service Bus in the [Azure SDK for JavaScript repository on GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/servicebus/service-bus/samples/v7).
30
+
31
+
If you're new to the service, see [Service Bus overview](service-bus-messaging-overview.md) before you begin.
29
32
30
33
## Prerequisites
31
34
32
-
If you're new to the service, see [Service Bus overview](service-bus-messaging-overview.md) before you do this quickstart.
35
+
- An Azure subscription. To complete this quickstart, you need an Azure account. You can activate your [Monthly Azure credits for Visual Studio subscribers](https://azure.microsoft.com/pricing/member-offers/credit-for-visual-studio-subscribers/?WT.mc_id=A85619ABF) or sign-up for a [free account](https://azure.microsoft.com/free/?WT.mc_id=A85619ABF).
33
36
34
-
- An Azure subscription. To complete this tutorial, you need an Azure account. You can activate your [MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/credit-for-visual-studio-subscribers/?WT.mc_id=A85619ABF) or sign-up for a [free account](https://azure.microsoft.com/free/?WT.mc_id=A85619ABF).
To use this quickstart with your own Azure account, you need:
40
-
* Install [Azure CLI](/cli/azure/install-azure-cli), which provides the passwordless authentication to your developer machine.
41
-
* Sign in with your Azure account at the terminal or command prompt with `az login`.
42
-
* Use the same account when you add the appropriate data role to your resource.
43
-
* Run the code in the same terminal or command prompt.
44
-
* Note down your **queue** name for your Service Bus namespace. You'll need that in the code.
41
+
To use this quickstart with your own Azure account:
42
+
43
+
- Install [Azure CLI](/cli/azure/install-azure-cli), which provides the passwordless authentication to your developer machine.
44
+
- Sign in with your Azure account at a command prompt with `az login`.
45
+
- Use the same account when you add the appropriate data role to your resource.
46
+
- Run the code in the same Command Prompt window.
47
+
- Make a note of your **queue** name for your Service Bus namespace. You need that in the code.
45
48
46
49
### [Connection string](#tab/connection-string)
47
50
48
-
Note down the following, which you'll use in the code below:
49
-
* Service Bus namespace **connection string**
50
-
* Service Bus namespace **queue** you created
51
+
Make a note of the following values to use in the code:
52
+
53
+
- Service Bus namespace **connection string**
54
+
- Service Bus namespace **queue** you created
51
55
52
56
---
53
57
@@ -65,23 +69,23 @@ Note down the following, which you'll use in the code below:
65
69
66
70
### [Passwordless](#tab/passwordless)
67
71
68
-
1. To install the required npm package(s) for Service Bus, open a command prompt that has `npm` in its path, change the directory to the folder where you want to have your samples and then run this command.
72
+
1. To install the required npm packages for Service Bus, open a Command Prompt window that has `npm` in its path and change the directory to the folder where you want to have your samples.
69
73
70
74
1. Install the following packages:
71
75
72
-
```bash
73
-
npm install @azure/service-bus @azure/identity
74
-
```
76
+
```bash
77
+
npm install @azure/service-bus @azure/identity
78
+
```
75
79
76
80
### [Connection string](#tab/connection-string)
77
81
78
-
1. To install the required npm package(s)forService Bus, open a command prompt that has `npm`in its path, change the directory to the folder where you want to have your samples and then run this command.
82
+
1. To install the required npm packages for Service Bus, open a Command Prompt window that has `npm` in its path and change the directory to the folder where you want to have your samples.
79
83
80
84
1. Install the following package:
81
85
82
-
```bash
83
-
npm install @azure/service-bus
84
-
```
86
+
```bash
87
+
npm install @azure/service-bus
88
+
```
85
89
86
90
---
87
91
@@ -91,13 +95,13 @@ The following sample code shows you how to send a message to a queue.
91
95
92
96
### [Passwordless](#tab/passwordless)
93
97
94
-
You must have signed in with the Azure CLI's `az login` in order for your local machine to provide the passwordless authentication required in this code.
98
+
Sign in with the Azure CLI command `az login` for your local machine to provide the passwordless authentication required in this code.
95
99
96
-
1. Open your favorite editor, such as [Visual Studio Code](https://code.visualstudio.com/).
97
-
1. Create a file called `send.js` and paste the below code into it. This code sends the names of scientists as messages to your queue.
100
+
1. Open a text editor, such as [Visual Studio Code](https://code.visualstudio.com/).
101
+
1. Create a file called `send.js` and paste the following code into it. This code sends the names of scientists as messages to your queue.
98
102
99
103
> [!IMPORTANT]
100
-
> The passwordless credential is provided with the [**DefaultAzureCredential**](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential).
104
+
> The passwordless credential is provided by using the [**DefaultAzureCredential**](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/identity/identity#defaultazurecredential).
@@ -400,14 +406,13 @@ You must have signed in with the Azure CLI's `az login` in order for your local
400
406
});
401
407
```
402
408
403
-
3. Replace `<CONNECTION STRING TO SERVICE BUS NAMESPACE>` with the connection string to your Service Bus namespace.
404
-
405
-
4. Replace `<QUEUE NAME>` with the name of the queue.
406
-
5. Then run the command in a command prompt to execute this file.
409
+
1. Replace `<CONNECTION STRING TO SERVICE BUS NAMESPACE>`with the connection string to your Service Bus namespace.
410
+
1. Replace `<QUEUE NAME>`with the name of the queue.
411
+
1. To run the code inthis file, use this command at a command prompt:
407
412
408
-
```console
409
-
node receive.js
410
-
```
413
+
```console
414
+
node receive.js
415
+
```
411
416
412
417
---
413
418
@@ -426,26 +431,27 @@ Received message: Johannes Kepler
426
431
Received message: Nikolaus Kopernikus
427
432
```
428
433
429
-
On the **Overview** page for the Service Bus namespace in the Azure portal, you can see **incoming** and **outgoing** message count. You may need to wait for a minute or so and then refresh the page to see the latest values.
434
+
On the **Overview** page for the Service Bus namespace in the Azure portal, you can see **incoming** and **outgoing** message count. Youmight need to wait for a minute or so and then refresh the page to see the latest values.
430
435
431
-
:::image type="content" source="./media/service-bus-java-how-to-use-queues/overview-incoming-outgoing-messages.png" alt-text="Incoming and outgoing message count":::
Select the queue on this**Overview** page to navigate to the **Service Bus Queue**page. You see the **incoming** and **outgoing** message count on this page too. You also see other information such as the **current size**of the queue, **maximum size**, **active message count**, and so on.
If you receive one of the following errors when running the **passwordless** version of the JavaScript code, make sure you are signed in via the Azure CLI command, `az login` and the [appropriate role](#azure-built-in-roles-for-azure-service-bus) is applied to your Azure user account:
444
+
If you receive one of the following errors when you run the **passwordless** version of the JavaScript code, sign inby using the Azure CLI command, `az login`. The[appropriate role](service-bus-nodejs-how-to-use-queues.md?tabs=passwordless#azure-built-in-roles-for-azure-service-bus) is applied to your Azure user account:
440
445
441
-
* 'Send' claim(s) are required to perform this operation
442
-
* 'Receive' claim(s) are required to perform this operation
446
+
-'Send'claims are required to perform this operation
447
+
-'Receive'claims are required to perform this operation
443
448
444
449
## Clean up resources
445
450
446
451
Navigate to your Service Bus namespace in the Azure portal, and select **Delete** on the Azure portal to delete the namespace and the queue in it.
447
452
448
-
## Next steps
453
+
## Related content
454
+
449
455
See the following documentation and samples:
450
456
451
457
- [Azure Service Bus client library for JavaScript](https://www.npmjs.com/package/@azure/service-bus)
0 commit comments