Skip to content

Commit 602b160

Browse files
Merge pull request #234147 from EldertGrootenboer/jms-migration-guide-passwordless
Updated docs with migration guide for JMS to passwordless
2 parents 0858b3d + d60afba commit 602b160

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

articles/service-bus-messaging/service-bus-migrate-azure-credentials.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,26 @@ Application requests to Azure Service Bus must be authenticated using either acc
2020

2121
The following code example demonstrates how to connect to Azure Service Bus using a connection string that includes an access key. When you create a Service Bus, Azure generates these keys and connection strings automatically. Many developers gravitate towards this solution because it feels familiar to options they've worked with in the past. If your application currently uses connection strings, consider migrating to passwordless connections using the steps described in this document.
2222

23+
# [C#](#tab/csharp)
24+
2325
```csharp
2426
var serviceBusClient = new ServiceBusClient(
2527
"<NAMESPACE-CONNECTION-STRING>",
2628
clientOptions);
2729
```
2830

31+
# [Java - JMS](#tab/java-jms)
32+
33+
```java
34+
ServiceBusJmsConnectionFactorySettings connFactorySettings = new ServiceBusJmsConnectionFactorySettings();
35+
connFactorySettings.setConnectionIdleTimeoutMS(20000);
36+
37+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(
38+
"<NAMESPACE-CONNECTION-STRING>",
39+
new ServiceBusJmsConnectionFactorySettings());
40+
```
41+
---
42+
2943
Connection strings should be used with caution. Developers must be diligent to never expose the keys in an unsecure location. Anyone who gains access to the key is able to authenticate. For example, if an account key is accidentally checked into source control, sent through an unsecure email, pasted into the wrong chat, or viewed by someone who shouldn't have permission, there's risk of a malicious user accessing the application. Instead, consider updating your application to use passwordless connections.
3044

3145
## Migrate to passwordless connections
@@ -48,6 +62,8 @@ For local development, make sure you're authenticated with the same Azure AD acc
4862

4963
Next you'll need to update your code to use passwordless connections.
5064

65+
# [C#](#tab/csharp)
66+
5167
1. To use `DefaultAzureCredential` in a .NET application, add the **Azure.Identity** NuGet package to your application.
5268

5369
```dotnetcli
@@ -77,6 +93,42 @@ Next you'll need to update your code to use passwordless connections.
7793

7894
1. Make sure to update the Service Bus namespace in the URI of your `ServiceBusClient`. You can find the namespace on the overview page of the Azure portal.
7995

96+
# [Java - JMS](#tab/java-jms)
97+
98+
1. To use `DefaultAzureCredential` in a JMS application, add at least version **1.0.0** of the **azure-servicebus-jms** package to your application.
99+
100+
```xml
101+
<dependency>
102+
<groupId>com.microsoft.azure</groupId>
103+
<artifactId>azure-servicebus-jms</artifactId>
104+
<version>1.0.0</version>
105+
</dependency>
106+
```
107+
108+
2. At the top of your file, add the following `import` statements:
109+
110+
```java
111+
import com.azure.core.credential.TokenCredential;
112+
import com.azure.identity.DefaultAzureCredentialBuilder;
113+
```
114+
115+
3. Identify the locations in your code that currently create a `ServiceBusJmsConnectionFactory` to connect to Azure Service Bus. Update your code to match the following example:
116+
117+
```java
118+
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder()
119+
.build();
120+
121+
ServiceBusJmsConnectionFactorySettings connFactorySettings = new ServiceBusJmsConnectionFactorySettings();
122+
connFactorySettings.setConnectionIdleTimeoutMS(20000);
123+
124+
//TODO: Replace the "<SERVICE-BUS-NAMESPACE-NAME>" placeholder.
125+
ConnectionFactory factory = new ServiceBusJmsConnectionFactory(tokenCredential, "<SERVICE-BUS-NAMESPACE-NAME>.servicebus.windows.net", connFactorySettings);
126+
```
127+
128+
4. Make sure to update the Service Bus namespace in the URI of your `ServiceBusJmsConnectionFactory`. You can find the namespace on the overview page of the Azure portal.
129+
130+
---
131+
80132
#### Run the app locally
81133

82134
After making these code changes, run your application locally. The new configuration should pick up your local credentials, such as the Azure CLI, Visual Studio, or IntelliJ. The roles you assigned to your local dev user in Azure will allow your app to connect to the Azure service locally.

0 commit comments

Comments
 (0)