Skip to content

Commit

Permalink
SB : Sample Disable queue from administration client (Azure#18236)
Browse files Browse the repository at this point in the history
Adding sample for administrator client.
  • Loading branch information
hemanttanwar authored Dec 18, 2020
1 parent 28ce31c commit 0123676
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ connection string value can be obtained by:
- [Receive messages from a specific session][ReceiveNamedSessionAsyncSample]
- [Receive messages from the first available session][ReceiveSingleSessionAsyncSample]

### Synchronous Administration Client operations
- [Update queue properties synchronously][AdministrationClientUpdateQueueSample]

## Troubleshooting
See [Troubleshooting][sdk_readme_troubleshooting].

Expand Down Expand Up @@ -83,5 +86,6 @@ Guidelines](https://github.com/Azure/azure-sdk-for-java/blob/master/CONTRIBUTING
[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
[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
[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
[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

![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 number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.messaging.servicebus;

import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient;
import com.azure.messaging.servicebus.administration.ServiceBusAdministrationClientBuilder;
import com.azure.messaging.servicebus.administration.models.QueueProperties;

import java.time.Duration;

/**
* Sample example showing how to update properties of Service Bus Queue.
*/
public class AdministrationClientUpdateQueueSample {
/**
* Main method to show how to update properties of Service Bus Queue.
*
* @param args Unused arguments to the program.
*/
public static void main(String[] args) {
// The connection string value can be obtained by:
// 1. Going to your Service Bus namespace in Azure Portal.
// 2. Go to "Shared access policies"
// 3. Copy the connection string for the "RootManageSharedAccessKey" policy.

String connectionString = "Endpoint={fully-qualified-namespace};SharedAccessKeyName={policy-name};"
+ "SharedAccessKey={key}";

// Create a administrator client using connection string.
ServiceBusAdministrationClient client = new ServiceBusAdministrationClientBuilder()
.connectionString(connectionString)
.buildClient();

// "<<queue-name>>" will be the name of the Service Bus queue instance you created
// inside the Service Bus namespace.
QueueProperties properties = client.getQueue("<<queue-name>>");

System.out.printf("Before queue properties LockDuration: [%d seconds], Max Delivery count: [%d].%n",
properties.getLockDuration().getSeconds(), properties.getMaxDeliveryCount());

// You can update 'QueueProperties' object with properties you want to change.
properties.setMaxDeliveryCount(10).setLockDuration(Duration.ofSeconds(60));

QueueProperties updatedProperties = client.updateQueue(properties);

System.out.printf("After queue properties LockDuration: [%d seconds], Max Delivery count: [%d].%n",
updatedProperties.getLockDuration().getSeconds(), updatedProperties.getMaxDeliveryCount());
}

}

0 comments on commit 0123676

Please sign in to comment.