Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[service-bus] Update readme to contain an actual snippet of code showing the constructor #11559

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions sdk/servicebus/service-bus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,47 @@ To use this client library in the browser, first you need to use a bundler. For

### Authenticate the client

Interaction with Service Bus starts with an instance of the [ServiceBusClient][sbclient] class.
Interaction with Service Bus starts with an instance of the [ServiceBusClient][sbclient] class. You can
authenticate to Service Bus using a connection string or using an Azure Active Directory credential.

You can instantiate this class using its constructors:
#### Using a connection string

- [Create using a connection string][sbclient_constructor]
- This method takes the connection string to your Service Bus instance. You can get the connection string
from the Azure portal.
- [Create using a TokenCredential][sbclient_tokencred_overload]
- This method takes the host name of your Service Bus instance and a credentials object that you need
to generate using the [@azure/identity](https://www.npmjs.com/package/@azure/identity)
library. The host name is of the format `name-of-service-bus-instance.servicebus.windows.net`.
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.
This method takes the connection string to your Service Bus instance. You can get
the connection string from the Azure portal.

```javascript
const { ServiceBusClient } = require("@azure/service-bus");

const serviceBusClient = new ServiceBusClient(connectionString);
```

More information about this constructor is available in the [API documentation][sbclient_constructor].

#### Using an Azure Active Directory Credential

Authentication with Azure Active Directory uses the [Azure Identity library][azure_identity].

The example below uses the [DefaultAzureCredential][defaultazurecredential], one of many
available credential providers from the `@azure/identity` library.

```javascript
const { ServiceBusClient } = require("@azure/service-bus");
const { DefaultAzureCredential } = require("@azure/identity");

const endpoint = "<name-of-service-bus-instance>.servicebus.windows.net";
const credential = new DefaultAzureCredential();
const serviceBusClient = new ServiceBusClient(endpoint, credential);
```

> NOTE: If you're using your own implementation of the `TokenCredential` interface
> against AAD, then set the "scopes" for service-bus to the following to get
> the appropriate token:

> ```typescript
> ["https://servicebus.azure.net//user_impersonation"]
> ```

More information about this constructor is available in the [API documentation][sbclient_tokencred_overload]

### Key concepts

Expand Down Expand Up @@ -342,6 +371,8 @@ If you'd like to contribute to this library, please read the [contributing guide
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fservicebus%2Fservice-bus%2FREADME.png)

[apiref]: https://aka.ms/azsdk/js/service-bus/docs
[azure_identity]: https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/identity/identity/README.md
[defaultazurecredential]: https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/identity/identity#defaultazurecredential
[sbclient]: https://docs.microsoft.com/javascript/api/%40azure/service-bus/servicebusclient?view=azure-node-preview
[sbclient_constructor]: https://docs.microsoft.com/javascript/api/@azure/service-bus/servicebusclient?view=azure-node-preview#servicebusclient-string--servicebusclientoptions-
[sbclient_tokencred_overload]: https://docs.microsoft.com/javascript/api/@azure/service-bus/servicebusclient?view=azure-node-preview#servicebusclient-string--tokencredential--servicebusclientoptions-
Expand Down