Skip to content

Commit 0123676

Browse files
authored
SB : Sample Disable queue from administration client (Azure#18236)
Adding sample for administrator client.
1 parent 28ce31c commit 0123676

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

sdk/servicebus/azure-messaging-servicebus/src/samples/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ connection string value can be obtained by:
5151
- [Receive messages from a specific session][ReceiveNamedSessionAsyncSample]
5252
- [Receive messages from the first available session][ReceiveSingleSessionAsyncSample]
5353

54+
### Synchronous Administration Client operations
55+
- [Update queue properties synchronously][AdministrationClientUpdateQueueSample]
56+
5457
## Troubleshooting
5558
See [Troubleshooting][sdk_readme_troubleshooting].
5659

@@ -83,5 +86,6 @@ Guidelines](https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING
8386
[SendScheduledMessageAndCancelAsyncSample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/SendScheduledMessageAndCancelAsyncSample.java
8487
[ServiceBusProcessorSample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusProcessorSample.java
8588
[ServiceBusSessionProcessorSample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusSessionProcessorSample.java
89+
[AdministrationClientUpdateQueueSample]: https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/AdministrationClientUpdateQueueSample.java
8690

8791
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fservicebus%2Fazure-messaging-servicebus%2Fsrc%2Fsamples%2FREADME.png)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.azure.messaging.servicebus;
5+
6+
import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient;
7+
import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClientBuilder;
8+
import com.azure.messaging.servicebus.administration.models.QueueProperties;
9+
10+
import java.time.Duration;
11+
12+
/**
13+
* Sample example showing how to update properties of Service Bus Queue.
14+
*/
15+
public class AdministrationClientUpdateQueueSample {
16+
/**
17+
* Main method to show how to update properties of Service Bus Queue.
18+
*
19+
* @param args Unused arguments to the program.
20+
*/
21+
public static void main(String[] args) {
22+
// The connection string value can be obtained by:
23+
// 1. Going to your Service Bus namespace in Azure Portal.
24+
// 2. Go to "Shared access policies"
25+
// 3. Copy the connection string for the "RootManageSharedAccessKey" policy.
26+
27+
String connectionString = "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};"
28+
+ "SharedAccessKey={key}";
29+
30+
// Create a administrator client using connection string.
31+
ServiceBusAdministrationClient client = new ServiceBusAdministrationClientBuilder()
32+
.connectionString(connectionString)
33+
.buildClient();
34+
35+
// "<<queue-name>>" will be the name of the Service Bus queue instance you created
36+
// inside the Service Bus namespace.
37+
QueueProperties properties = client.getQueue("<<queue-name>>");
38+
39+
System.out.printf("Before queue properties LockDuration: [%d seconds], Max Delivery count: [%d].%n",
40+
properties.getLockDuration().getSeconds(), properties.getMaxDeliveryCount());
41+
42+
// You can update 'QueueProperties' object with properties you want to change.
43+
properties.setMaxDeliveryCount(10).setLockDuration(Duration.ofSeconds(60));
44+
45+
QueueProperties updatedProperties = client.updateQueue(properties);
46+
47+
System.out.printf("After queue properties LockDuration: [%d seconds], Max Delivery count: [%d].%n",
48+
updatedProperties.getLockDuration().getSeconds(), updatedProperties.getMaxDeliveryCount());
49+
}
50+
51+
}

0 commit comments

Comments
 (0)