[Service Bus] Add batch delete and purge APIs - #50318
[Service Bus] Add batch delete and purge APIs#50318Eldert Grootenboer (EldertGrootenboer) wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Multiple newly-added Javadoc blocks have broken indentation/misaligned tags that are likely to fail style checks and should be corrected before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds new receiver-level management operations to azure-messaging-servicebus to support batch message deletion and client-driven purging (sync + async), along with supporting models, tests, samples, and changelog documentation.
Changes:
- Added
deleteMessages(...)andpurgeMessages(...)APIs toServiceBusReceiverAsyncClientandServiceBusReceiverClient. - Implemented the
com.microsoft:batch-delete-messagesAMQP management operation in the management channel layer. - Added new option/result model types plus tests and JavaDoc code samples covering expected behaviors.
File summaries
| File | Description |
|---|---|
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java | Adds async delete/purge APIs and purge loop implementation. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverClient.java | Adds sync delete/purge APIs that delegate to async. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/ManagementChannel.java | Implements the batch delete management request/response handling. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/ManagementConstants.java | Introduces management wire keys/operation constant for batch delete. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/implementation/ServiceBusManagementNode.java | Extends management node contract with deleteMessages operation. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/models/DeleteMessagesOptions.java | Adds delete operation options model. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/models/DeleteMessagesResult.java | Adds delete operation result model. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/models/PurgeMessagesOptions.java | Adds purge operation options model. |
| sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/models/PurgeMessagesResult.java | Adds purge operation result model. |
| sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClientTest.java | Adds receiver-level unit tests for delete/purge behaviors. |
| sdk/servicebus/azure-messaging-servicebus/src/test/java/com/azure/messaging/servicebus/implementation/ManagementChannelTests.java | Adds management-channel tests for batch delete request/response validation. |
| sdk/servicebus/azure-messaging-servicebus/src/samples/java/com/azure/messaging/servicebus/ServiceBusReceiverClientJavaDocCodeSamples.java | Adds JavaDoc samples demonstrating delete and purge usage. |
| sdk/servicebus/azure-messaging-servicebus/CHANGELOG.md | Documents the new receiver delete/purge feature. |
Review details
Suppressed comments (7)
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverClient.java:358
- Javadoc formatting is broken here (mis-indented
*lines and@throwstags). Please reformat to match the surrounding Javadoc style so Checkstyle/JavadocStyle passes consistently.
/**
* Deletes up to {@code maxMessages} messages from the Service Bus entity.
* The SDK sends the destructive request once and surfaces any failure without automatically dispatching it again.
*
* @param maxMessages The maximum number of messages to delete. The service limit is 500 for Basic and Standard and
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverClient.java:375
- Javadoc formatting is inconsistent in this new public API block (misaligned leading
*). This can trip Javadoc formatting checks; please normalize indentation and wrap long lines consistently.
/**
* Purges messages enqueued before the purge started. The purge start time stays unchanged for every request, so
* newer messages remain. Large messages can produce smaller batches, which purge continues processing.
* Currently, purge is not supported when partitioning is enabled.
* If an error, cancellation, or timeout occurs after dispatch, the purge can be partial and its exact deletion
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverClient.java:390
- Javadoc formatting is inconsistent in this overload (misaligned leading
*and tags). Please reformat to match the repo's standard Javadoc indentation.
/**
* Purges messages enqueued before the configured time. That time stays unchanged for every request, so newer
* messages remain. Large messages can produce smaller batches, which purge continues processing. Currently,
* purge is not supported when partitioning is enabled. If an error, cancellation, or timeout occurs after
* dispatch, the purge can be partial and its exact deletion outcome is unknown.
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java:936
- This Javadoc block has misaligned indentation and tags (lines missing the standard leading
*). Please reformat for consistency and to avoid Checkstyle/JavadocStyle failures.
/**
* Permanently deletes up to {@code maxMessages} eligible messages from the Service Bus entity or subqueue.
* The operation is best effort and may return a short positive count. Locked, deferred, and scheduled messages are
* not eligible. A dispatched request is not automatically retried and an error can leave an unknown outcome.
*
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java:976
- The new purge API Javadoc has several lines missing the standard leading
*indentation. Please reformat the Javadoc to match surrounding style and avoid documentation-style check failures.
/**
* Permanently purges eligible messages enqueued before the purge started. The purge start time stays unchanged
* for every request, so newer messages remain. Large messages can produce smaller batches, which purge continues
* processing. Locked, deferred, and scheduled messages remain. Currently, purge is not supported when partitioning
* is enabled.
* If an error, cancellation, or timeout occurs after dispatch, the purge can be partial and its exact deletion
* outcome is unknown.
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/ServiceBusReceiverAsyncClient.java:992
- This overload's Javadoc is missing consistent leading
*indentation on several lines and has misaligned tags. Please reformat for consistency (and to keep Checkstyle/JavadocStyle happy).
/**
* Permanently purges eligible messages enqueued before the configured time, using that same time and request size
* for every request. Large messages can produce smaller batches, which purge continues processing. Locked,
* deferred, and scheduled messages remain. Currently, purge is not supported when partitioning is enabled.
* If an error, cancellation, or timeout occurs after dispatch, the purge can be partial and its exact deletion
* outcome is unknown.
*
sdk/servicebus/azure-messaging-servicebus/src/main/java/com/azure/messaging/servicebus/models/PurgeMessagesOptions.java:58
- Javadoc indentation is inconsistent in this setter (missing leading
*on multiple lines and misaligned@throws). Please reformat to match the repo's Javadoc style.
/**
* Sets the maximum number of messages requested in each batch-delete call. The service limit is 500 for Basic and
* Standard and 4,000 for Premium.
*
* @param maxMessagesPerBatch The positive maximum number of messages per batch.
* @return The updated {@link PurgeMessagesOptions}.
* @throws IllegalArgumentException if {@code maxMessagesPerBatch} is less than one.
*/
- Files reviewed: 13/13 changed files
- Comments generated: 6
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| /** | ||
| * Permanently deletes up to {@code maxMessages} eligible messages from the Service Bus entity or subqueue. | ||
| * Large messages can cause the service to delete fewer messages than requested. Locked, deferred, and scheduled | ||
| * messages are not eligible. Currently, batch delete is not supported when partitioning is enabled. | ||
| * | ||
| * <p>The SDK sends the destructive request once. If an error, cancellation, or timeout occurs, the deletion outcome | ||
| * is unknown and the request is not automatically dispatched again.</p> | ||
| * | ||
| * @param maxMessages The positive maximum number of messages to delete. The service limit is 500 for Basic and | ||
| * Standard and 4,000 for Premium. | ||
| * @return The result containing the number of messages actually deleted by the service. | ||
| * @throws IllegalArgumentException if {@code maxMessages} is not positive. | ||
| * @throws IllegalStateException if the receiver is already disposed. | ||
| * @throws ServiceBusException if the request fails. | ||
| */ |
| /** | ||
| * Deletes up to {@code maxMessages} messages from the Service Bus entity. | ||
| * The SDK sends the destructive request once and surfaces any failure without automatically dispatching it again. | ||
| * | ||
| * @param maxMessages The maximum number of messages to delete. The service limit is 500 for Basic and Standard and | ||
| * 4,000 for Premium. Currently, batch delete is not supported when partitioning is enabled. | ||
| * @return The result containing the number of messages actually deleted by the service. | ||
| * @throws IllegalArgumentException if {@code maxMessages} is not positive. | ||
| * @throws IllegalStateException if the receiver is already disposed. | ||
| * @throws ServiceBusException if the request fails. | ||
| */ |
| /** | ||
| * Deletes up to {@code maxMessages} messages enqueued before the given cutoff. | ||
| * | ||
| * @param maxMessages The maximum number of messages to delete. The service limit is 500 for Basic and Standard | ||
| * and 4,000 for Premium. | ||
| * @param enqueueTimeUtcOlderThan Only messages enqueued before this time are deleted. | ||
| * @param sessionId The session identifier, or {@code null} for a non-session entity. | ||
| * @param associatedLinkName The associated receive-link name, or {@code null} if no link is open. | ||
| * @return The number of messages actually deleted by the service. | ||
| */ |
| /** | ||
| * Gets the enqueue-time cutoff. Only messages enqueued before this time are eligible for deletion. | ||
| * | ||
| * @return The enqueue-time cutoff, or {@code null} to use the time the operation starts. | ||
| */ |
| /** | ||
| * Gets the enqueue-time threshold that stays unchanged for every purge request. | ||
| * | ||
| * @return The enqueue-time threshold, or {@code null} to use the time the purge starts. | ||
| */ |
| final Map<String, Object> appProperties = sentMessage.getApplicationProperties().getValue(); | ||
| assertEquals("com.microsoft:batch-delete-messages", appProperties.get(MANAGEMENT_OPERATION_KEY)); | ||
| assertEquals(OPERATION_BATCH_DELETE_MESSAGES, appProperties.get(MANAGEMENT_OPERATION_KEY)); |
Description
Azure Service Bus exposes the
com.microsoft:batch-delete-messagesmanagement operation. This PR adds synchronous and asynchronous receiver-level batch-delete and purge APIs toazure-messaging-servicebusfor regular, session, and subqueue receivers.Purge captures one enqueue-time cutoff, defaults to 500 messages per request, continues after every positive result, and stops only when the service returns zero. Callers can select another positive request size; Service Bus enforces the current tier limit of 500 for Basic and Standard and 4,000 for Premium.
The management operation validates successful and message-not-found aggregate counts and does not turn a missing or malformed count into successful exhaustion. Samples cover default purge, Premium sizing, sessions, enqueue-time thresholds, returned counts, and partial or unknown outcomes.
Companion implementations: JavaScript, .NET, Python, and Go.
Testing: the full package suite completed with 1,049 tests and 292 skipped, with no failures or errors. The final focused receiver suite passes 103 tests, and management response coverage passes in the focused implementation suite.
Checklist