|
| 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