There are 2 ways you can work with the samples.
- Copy the sample file you want to a folder of your choice and run
npm install @azure/service-bus
to install the library - Or, in case you have cloned this repo, then run
npm install
in thesamples
folder to install the library. This will install the library as well as other dependencies that are required by some of the samples.
- In the Azure Portal, go to Dashboard > Service Bus > your-servicebus-namespace.
- If you don't have a Service Bus resource, then here are the docs which can help you create a Service Bus resource in the portal : Service Bus - Node.js docs.
- Note down the "Primary Connection String" of RootManageSharedAccessKey at Shared access policies under Settings tab.
- To work with Queues, find the "Queues" tab right under "Entities" at your-servicebus-namespace, create a Queue and note down its name.
- To work with Topics, find the "Topics" tab right under "Entities" at your-servicebus-namespace, create a Topic. Go to your-servicebus-namespace > your-topic, create subscriptions for the topic. Note down the names of the topic and subscriptions.
Note : RootManageSharedAccessKey is automatically created for the namespace and has permissions for the entire namespace. If you want to use restricted access, refer Shared Access Signatures, create the Access Keys exclusive to the specific created Queue/Topic.
Before running any of the samples, update it with the connection string and the queue/topic/subscription names you have noted down above.
Copy the sample to your samples folder and use node
to run it.
node sample.js
If you don't have Typescript installed, then use npm
to install it first.
npm install -g typescript
One way to run Typescript samples is to use ts-node
. To install ts-node
, run the below in your sample folder
npm install ts-node
Copy the sample to your samples folder and use ts-node
to run it.
ts-node sample.ts