ServiceBusAdministrationClient Class
- java.
lang. Object - com.
azure. messaging. servicebus. administration. ServiceBusAdministrationClient
- com.
public final class ServiceBusAdministrationClient
A synchronous client for managing a Service Bus namespace. Instantiated via ServiceBusAdministrationClientBuilder.
Sample: Create the async client
The follow code sample demonstrates the creation of the async administration client. The credential used in the following sample is DefaultAzureCredential
for authentication. It is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using managed identity for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the Azure Identity documentation.
HttpLogOptions logOptions = new HttpLogOptions()
.setLogLevel(HttpLogDetailLevel.HEADERS);
// DefaultAzureCredential creates a credential based on the environment it is executed in.
TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();
// 'fullyQualifiedNamespace' will look similar to "{your-namespace}.servicebus.windows.net"
ServiceBusAdministrationClient client = new ServiceBusAdministrationClientBuilder()
.credential(fullyQualifiedNamespace, tokenCredential)
.httpLogOptions(logOptions)
.buildClient();
Sample: Create a queue
The following sample creates a queue with default values. Default values are listed in CreateQueueOptions().
QueueProperties queue = client.createQueue("my-new-queue");
System.out.printf("Queue created. Name: %s. Lock Duration: %s.%n",
queue.getName(), queue.getLockDuration());
Sample: Edit an existing subscription
The following code sample demonstrates updating an existing subscription. Users should fetch the subscription's properties, modify the properties, and then pass the object to update method.
// To update the subscription we have to:
// 1. Get the subscription info from the service.
// 2. Update the SubscriptionProperties we want to change.
// 3. Call the updateSubscription() with the updated object.
SubscriptionProperties subscription = client.getSubscription("my-topic", "my-subscription");
System.out.println("Original delivery count: " + subscription.getMaxDeliveryCount());
// Updating it to a new value.
subscription.setMaxDeliveryCount(5);
// Persisting the updates to the subscription object.
SubscriptionProperties updated = client.updateSubscription(subscription);
System.out.printf("Subscription updated. Name: %s. Delivery count: %s.%n",
updated.getSubscriptionName(), updated.getMaxDeliveryCount());
Sample: List all queues
The following code sample lists all the queues in the Service Bus namespace.
client.listQueues().forEach(queue -> {
System.out.printf("Queue [%s]. Lock Duration: %s.%n",
queue.getName(), queue.getLockDuration());
});
Sample: Delete queue
The code sample below demonstrates deleting an existing queue.
try {
client.deleteQueue("my-existing-queue");
} catch (AzureException exception) {
System.err.println("Exception occurred deleting queue: " + exception);
}
Method Summary
Methods inherited from java.lang.Object
Method Details
createQueue
public QueueProperties createQueue(String queueName)
Creates a queue with the given name.
Parameters:
Returns:
createQueue
public QueueProperties createQueue(String queueName, CreateQueueOptions queueOptions)
Creates a queue with the CreateQueueOptions.
Parameters:
Returns:
createQueueWithResponse
public Response
Creates a queue and returns the created queue in addition to the HTTP response.
Parameters:
Returns:
createRule
public RuleProperties createRule(String topicName, String subscriptionName, String ruleName)
Creates a rule under the given topic and subscription
Parameters:
Returns:
createRule
public RuleProperties createRule(String topicName, String ruleName, String subscriptionName, CreateRuleOptions ruleOptions)
Creates a rule with the CreateRuleOptions.
Parameters:
Returns:
createRuleWithResponse
public Response
Creates a rule and returns the created rule in addition to the HTTP response.
Parameters:
Returns:
createSubscription
public SubscriptionProperties createSubscription(String topicName, String subscriptionName)
Creates a subscription with the given topic and subscription names.
Parameters:
Returns:
createSubscription
public SubscriptionProperties createSubscription(String topicName, String subscriptionName, CreateSubscriptionOptions subscriptionOptions)
Creates a subscription with the CreateSubscriptionOptions.
Parameters:
Returns:
createSubscription
public SubscriptionProperties createSubscription(String topicName, String subscriptionName, String ruleName, CreateSubscriptionOptions subscriptionOptions, CreateRuleOptions ruleOptions)
Creates a subscription with default rule using the CreateSubscriptionOptions and CreateRuleOptions.
Parameters:
Returns:
createSubscriptionWithResponse
public Response
Creates a subscription and returns the created subscription in addition to the HTTP response.
Parameters:
Returns:
createSubscriptionWithResponse
public Response
Creates a subscription with default rule configured and returns the created subscription in addition to the HTTP response.
Parameters:
Returns:
createTopic
public TopicProperties createTopic(String topicName)
Creates a topic with the given name.
Parameters:
Returns:
createTopic
public TopicProperties createTopic(String topicName, CreateTopicOptions topicOptions)
Creates a topic with the CreateTopicOptions.
Parameters:
Returns:
createTopicWithResponse
public Response
Creates a topic and returns the created topic in addition to the HTTP response.
Parameters:
Returns:
deleteQueue
public void deleteQueue(String queueName)
Deletes a queue the matching queueName
.
Parameters:
deleteQueueWithResponse
public Response
Deletes a queue the matching queueName
and returns the HTTP response.
Parameters:
Returns:
deleteRule
public void deleteRule(String topicName, String subscriptionName, String ruleName)
Deletes a rule the matching ruleName
.
Parameters:
deleteRuleWithResponse
public Response
Deletes a rule the matching ruleName
and returns the HTTP response.
Parameters:
Returns:
deleteSubscription
public void deleteSubscription(String topicName, String subscriptionName)
Deletes a subscription matching the subscriptionName
in topic topicName
.
Parameters:
deleteSubscriptionWithResponse
public Response
Deletes a subscription the matching subscriptionName
and returns the HTTP response.
Parameters:
Returns:
deleteTopic
public void deleteTopic(String topicName)
Deletes a topic the matching topicName
.
Parameters:
deleteTopicWithResponse
public Response
Deletes a topic the matching topicName
and returns the HTTP response.
Parameters:
Returns:
getNamespaceProperties
public NamespaceProperties getNamespaceProperties()
Gets information about the Service Bus namespace.
Returns:
getNamespacePropertiesWithResponse
public Response
Gets information about the Service Bus namespace along with its HTTP response.
Parameters:
Returns:
getQueue
public QueueProperties getQueue(String queueName)
Gets information about the queue.
Parameters:
Returns:
getQueueExists
public boolean getQueueExists(String queueName)
Gets whether a queue with queueName
exists in the Service Bus namespace.
Parameters:
Returns:
true
if the queue exists; otherwise false
.getQueueExistsWithResponse
public Response
Gets whether a queue with queueName
exists in the Service Bus namespace.
Parameters:
Returns:
true
if the queue exists; otherwise false
.getQueueRuntimeProperties
public QueueRuntimeProperties getQueueRuntimeProperties(String queueName)
Gets runtime properties about the queue.
Parameters:
Returns:
getQueueRuntimePropertiesWithResponse
public Response
Gets runtime properties about the queue along with its HTTP response.
Parameters:
Returns:
getQueueWithResponse
public Response
Gets information about the queue along with its HTTP response.
Parameters:
Returns:
getRule
public RuleProperties getRule(String topicName, String subscriptionName, String ruleName)
Gets a rule from the service namespace. Only following data types are deserialized in Filters and Action parameters - string, int, long, boolean, double, and OffsetDateTime. Other data types would return its string value.
Parameters:
Returns:
getRuleWithResponse
public Response
Gets a rule from the service namespace. Only following data types are deserialized in Filters and Action parameters - string, int, long, bool, double, and OffsetDateTime. Other data types would return its string value.
Parameters:
Returns:
getSubscription
public SubscriptionProperties getSubscription(String topicName, String subscriptionName)
Gets information about the queue.
Parameters:
Returns:
getSubscriptionExists
public boolean getSubscriptionExists(String topicName, String subscriptionName)
Gets whether a subscription within a topic exists.
Parameters:
Returns:
true
if the subscription exists.getSubscriptionExistsWithResponse
public Response
Gets whether a subscription within a topic exists.
Parameters:
Returns:
true
if the subscription exists; otherwise false
.getSubscriptionRuntimeProperties
public SubscriptionRuntimeProperties getSubscriptionRuntimeProperties(String topicName, String subscriptionName)
Gets runtime properties about the subscription.
Parameters:
Returns:
getSubscriptionRuntimePropertiesWithResponse
public Response
Gets runtime properties about the subscription.
Parameters:
Returns:
getSubscriptionWithResponse
public Response
Gets information about the subscription along with its HTTP response.
Parameters:
Returns:
getTopic
public TopicProperties getTopic(String topicName)
Gets information about the topic.
Parameters:
Returns:
getTopicExists
public boolean getTopicExists(String topicName)
Gets whether a topic with topicName
exists in the Service Bus namespace.
Parameters:
Returns:
true
if the topic exists.getTopicExistsWithResponse
public Response
Gets whether a topic with topicName
exists in the Service Bus namespace.
Parameters:
Returns:
true
if the topic exists; otherwise false
.getTopicRuntimeProperties
public TopicRuntimeProperties getTopicRuntimeProperties(String topicName)
Gets runtime properties about the topic.
Parameters:
Returns:
getTopicRuntimePropertiesWithResponse
public Response
Gets runtime properties about the topic with its HTTP response.
Parameters:
Returns:
getTopicWithResponse
public Response
Gets information about the topic along with its HTTP response.
Parameters:
Returns:
listQueues
public PagedIterable
Fetches all the queues in the Service Bus namespace.
Returns:
listQueues
public PagedIterable
Fetches all the queues in the Service Bus namespace.
Parameters:
Returns:
listRules
public PagedIterable
Fetches all the rules for a topic and subscription.
Parameters:
Returns:
listRules
public PagedIterable
Fetches all the rules for a topic and subscription.
Parameters:
Returns:
listSubscriptions
public PagedIterable
Fetches all the subscriptions for a topic.
Parameters:
Returns:
topicName
.listSubscriptions
public PagedIterable
Fetches all the subscriptions for a topic.
Parameters:
Returns:
topicName
.listTopics
public PagedIterable
Fetches all the topics in the Service Bus namespace.
Returns:
listTopics
public PagedIterable
Fetches all the topics in the Service Bus namespace.
Parameters:
Returns:
updateQueue
public QueueProperties updateQueue(QueueProperties queue)
Updates a queue with the given QueueProperties. The QueueProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getQueue(String queueName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setLockDuration(Duration lockDuration)
- setDuplicateDetectionHistoryTimeWindow(Duration duplicateDetectionHistoryTimeWindow)
- setMaxDeliveryCount(Integer maxDeliveryCount)
Parameters:
Returns:
updateQueueWithResponse
public Response
Updates a queue with the given QueueProperties. The QueueProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getQueue(String queueName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setLockDuration(Duration lockDuration)
- setDuplicateDetectionHistoryTimeWindow(Duration duplicateDetectionHistoryTimeWindow)
- setMaxDeliveryCount(Integer maxDeliveryCount)
Parameters:
Returns:
updateRule
public RuleProperties updateRule(String topicName, String subscriptionName, RuleProperties rule)
Updates a rule with the given RuleProperties. The RuleProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getRule(String topicName, String subscriptionName, String ruleName)
- Update the required elements.
- Pass the updated description into this method.
Parameters:
Returns:
updateRuleWithResponse
public Response
Updates a rule with the given RuleProperties. The RuleProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getRule(String topicName, String subscriptionName, String ruleName)
- Update the required elements.
- Pass the updated description into this method.
Parameters:
Returns:
updateSubscription
public SubscriptionProperties updateSubscription(SubscriptionProperties subscription)
Updates a subscription with the given SubscriptionProperties. The SubscriptionProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getSubscription(String topicName, String subscriptionName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setLockDuration(Duration lockDuration)
- setMaxDeliveryCount(int maxDeliveryCount)
Parameters:
Returns:
updateSubscriptionWithResponse
public Response
Updates a subscription with the given SubscriptionProperties. The SubscriptionProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getSubscription(String topicName, String subscriptionName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setLockDuration(Duration lockDuration)
- setMaxDeliveryCount(int maxDeliveryCount)
Parameters:
Returns:
updateTopic
public TopicProperties updateTopic(TopicProperties topic)
Updates a topic with the given TopicProperties. The TopicProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getTopic(String topicName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setDuplicateDetectionHistoryTimeWindow(Duration duplicateDetectionHistoryTimeWindow)
Parameters:
Returns:
updateTopicWithResponse
public Response
Updates a topic with the given TopicProperties. The TopicProperties must be fully populated as all the properties are replaced. If a property is not set the service default value is used. The suggested flow is:
- getTopic(String topicName)
- Update the required elements.
- Pass the updated description into this method.
There are a subset of properties that can be updated. More information can be found in the links below. They are:
- setDefaultMessageTimeToLive(Duration defaultMessageTimeToLive)
- setDuplicateDetectionHistoryTimeWindow(Duration duplicateDetectionHistoryTimeWindow)
Parameters:
Returns:
Applies to
Azure SDK for Java