azure-docs-sdk-java/docs-ref-autogen/com.azure.messaging.service...

15 строки
9.0 KiB
YAML

### YamlMime:JavaPackage
uid: "com.azure.messaging.servicebus.administration"
fullName: "com.azure.messaging.servicebus.administration"
name: "com.azure.messaging.servicebus.administration"
summary: "The Azure Service Bus Administration client library allows for management of entities in their Service Bus namespace."
classes:
- "com.azure.messaging.servicebus.administration.ServiceBusAdministrationAsyncClient"
- "com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient"
- "com.azure.messaging.servicebus.administration.ServiceBusAdministrationClientBuilder"
- "com.azure.messaging.servicebus.administration.ServiceBusSupplementaryAuthHeaderPolicy"
desc: "The Azure Service Bus Administration client library allows for management of entities in their Service Bus namespace. It can be used to create, delete, update, or list queues, topics, rules, and subscriptions.\n\n[Microsoft Azure Service Bus][] is a fully managed enterprise integration message broker. Service Bus can decouple applications and services. Service Bus offers a reliable and secure platform for asynchronous transfer of data and state. Data is transferred between different applications and services using messages.\n\n## Key Concepts ##\n\n * **[Queue][] :** Allows for the sending and receiving of messages, ordered first-in-first-out (FIFO). It is often used for point to point communication.\n * **[Topic][] :** Allows for sending messages to multiple receivers, simultaneously. This is suited for publisher and subscriber scenarios.\n * **[ Subscription][Subscription]:** Receives messages from a topic. Each subscription is independent and receives a copy of every message sent to the topic. Each subscription has a filter. Filters, also known as rules, are applied to each message to determine whether they will be published to the subscription.\n * **Rule Filters:** A filter, associated with a subscription, that is tested against every message sent to a Service Bus topic. If the filter returns true, a copy of the message is published to that subscription. There are 3 types of filters: SQL filters, boolean filters, and correlation filters. More information can be found in: [ Topic filters][Topic filters].\n * **[Rule Actions ][Rule Actions]:** A modification applied to a Service Bus message when it matches the associated rule filter.\n\n## Getting Started ##\n\nService clients are the point of interaction for developers to use Azure Service Bus. <xref uid=\"com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.messaging.servicebus.administration.ServiceBusAdministrationClient\"></xref> and <xref uid=\"com.azure.messaging.servicebus.administration.ServiceBusAdministrationAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.messaging.servicebus.administration.ServiceBusAdministrationAsyncClient\"></xref> are the sync and async clients for managing entities in the Service Bus namespace.\n\nThe examples shown in this document use a credential object named DefaultAzureCredential for authentication, which 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][].\n\n### Creating clients ###\n\n**Sample: Create a ServiceBusAdministrationClient**\n\nThe following code sample demonstrates the creation of the synchronous administration client.\n\n```java\nHttpLogOptions logOptions = new HttpLogOptions()\n .setLogLevel(HttpLogDetailLevel.HEADERS);\n\n // DefaultAzureCredential creates a credential based on the environment it is executed in.\n TokenCredential tokenCredential = new DefaultAzureCredentialBuilder().build();\n\n // 'fullyQualifiedNamespace' will look similar to \"{your-namespace}.servicebus.windows.net\"\n ServiceBusAdministrationClient client = new ServiceBusAdministrationClientBuilder()\n .credential(fullyQualifiedNamespace, tokenCredential)\n .httpLogOptions(logOptions)\n .buildClient();\n```\n\n### Managing queues ###\n\n**Sample: Create a queue**\n\nThe following code sample demonstrates the creation of a Service Bus queue with some configured options. If <xref uid=\"com.azure.messaging.servicebus.administration.models.CreateQueueOptions\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.messaging.servicebus.administration.models.CreateQueueOptions\"></xref> are not passed in, default values are used to create the queue.\n\n```java\nCreateQueueOptions queueOptions = new CreateQueueOptions()\n .setLockDuration(Duration.ofMinutes(2))\n .setMaxDeliveryCount(15);\n\n QueueProperties queue = client.createQueue(\"my-new-queue\", queueOptions);\n System.out.printf(\"Queue created. Name: %s. Lock Duration: %s.%n\",\n queue.getName(), queue.getLockDuration());\n```\n\n**Sample: Update a queue**\n\nThe following code sample demonstrates updating a Service bus queue. Users should fetch the queue's properties, modify the properties, and then pass the object to update method.\n\n```java\nQueueProperties queue = client.getQueue(\"queue-that-exists\");\n\n queue.setLockDuration(Duration.ofMinutes(3))\n .setMaxDeliveryCount(15)\n .setDeadLetteringOnMessageExpiration(true);\n\n QueueProperties updatedQueue = client.updateQueue(queue);\n\n System.out.printf(\"Queue updated. Name: %s. Lock duration: %s. Max delivery count: %s.%n\",\n updatedQueue.getName(), updatedQueue.getLockDuration(), updatedQueue.getMaxDeliveryCount());\n```\n\n### Managing topics and subscriptions ###\n\n**Sample: Create a topic, subscription, and rule**\n\nThe following code sample demonstrates the creation of a Service Bus topic and subscription. The subscription filters for messages with a correlation id `\"emails\"` and has a `\"importance\"` property set to `\"high\"`. Consequently, all high importance Service Bus messages will be delivered to the `\"high-importance-subscription\"` subscription. See [Topic filters][] for additional information.\n\n```java\nString topicName = \"my-new-topic\";\n TopicProperties topic = client.createTopic(topicName);\n\n String subscriptionName = \"high-importance-subscription\";\n String ruleName = \"important-emails-filter\";\n CreateSubscriptionOptions subscriptionOptions = new CreateSubscriptionOptions()\n .setMaxDeliveryCount(15)\n .setLockDuration(Duration.ofMinutes(2));\n\n CorrelationRuleFilter ruleFilter = new CorrelationRuleFilter()\n .setCorrelationId(\"emails\");\n ruleFilter.getProperties().put(\"importance\", \"high\");\n\n CreateRuleOptions createRuleOptions = new CreateRuleOptions()\n .setFilter(ruleFilter);\n\n SubscriptionProperties subscription = client.createSubscription(topicName, subscriptionName, ruleName,\n subscriptionOptions, createRuleOptions);\n\n System.out.printf(\"Subscription created. Name: %s. Topic name: %s. Lock Duration: %s.%n\",\n subscription.getSubscriptionName(), subscription.getTopicName(), subscription.getLockDuration());\n```\n\n**Sample: Update a subscription**\n\nThe following code sample demonstrates updating an existing subscription. Users should fetch the subscription, modify the properties, and pass that object into the update method.\n\n```java\n// To update the subscription we have to:\n // 1. Get the subscription info from the service.\n // 2. Update the SubscriptionProperties we want to change.\n // 3. Call the updateSubscription() with the updated object.\n SubscriptionProperties subscription = client.getSubscription(\"my-topic\", \"my-subscription\");\n\n System.out.println(\"Original delivery count: \" + subscription.getMaxDeliveryCount());\n\n // Updating it to a new value.\n subscription.setMaxDeliveryCount(5);\n\n // Persisting the updates to the subscription object.\n SubscriptionProperties updated = client.updateSubscription(subscription);\n\n System.out.printf(\"Subscription updated. Name: %s. Delivery count: %s.%n\",\n updated.getSubscriptionName(), updated.getMaxDeliveryCount());\n```\n\n\n[Microsoft Azure Service Bus]: https://docs.microsoft.com/azure/service-bus-messaging\n[Queue]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-messaging-overview#queues\n[Topic]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-messaging-overview#topics\n[Subscription]: https://docs.microsoft.com/azure/service-bus-messaging/service-bus-queues-topics-subscriptions#topics-and-subscriptions\n[Topic filters]: https://learn.microsoft.com/azure/service-bus-messaging/topic-filters\n[Rule Actions]: https://learn.microsoft.com/azure/service-bus-messaging/topic-filters#actions\n[managed identity]: https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/\n[Azure Identity documentation]: https://learn.microsoft.com/java/api/overview/azure/identity-readme"
metadata: {}
package: "com.azure.messaging.servicebus.administration"
artifact: com.azure:azure-messaging-servicebus:7.17.3