Skip to content

[Service Bus] Add batch delete and purge APIs - #50318

Draft
Eldert Grootenboer (EldertGrootenboer) wants to merge 1 commit into
mainfrom
fix/servicebus-batch-delete
Draft

[Service Bus] Add batch delete and purge APIs#50318
Eldert Grootenboer (EldertGrootenboer) wants to merge 1 commit into
mainfrom
fix/servicebus-batch-delete

Conversation

@EldertGrootenboer

Copy link
Copy Markdown
Member

Description

Azure Service Bus exposes the com.microsoft:batch-delete-messages management operation. This PR adds synchronous and asynchronous receiver-level batch-delete and purge APIs to azure-messaging-servicebus for regular, session, and subqueue receivers.

DeleteMessagesResult deleteMessages(int maxMessages);
DeleteMessagesResult deleteMessages(int maxMessages, DeleteMessagesOptions options);
PurgeMessagesResult purgeMessages();
PurgeMessagesResult purgeMessages(PurgeMessagesOptions options);

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

  • No REST spec or generator change applies; this is a handwritten AMQP client operation.
  • CHANGELOG is updated.
  • Tests and JavaDoc samples are included.
  • Public API follows the existing synchronous and reactive client patterns.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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(...) and purgeMessages(...) APIs to ServiceBusReceiverAsyncClient and ServiceBusReceiverClient.
  • Implemented the com.microsoft:batch-delete-messages AMQP 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 @throws tags). 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.

Comment on lines +913 to +927
/**
* 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.
*/
Comment on lines +339 to +349
/**
* 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.
*/
Comment on lines +128 to +137
/**
* 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.
*/
Comment on lines +20 to +24
/**
* 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.
*/
Comment on lines +21 to +25
/**
* 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.
*/
Comment on lines +1504 to +1506
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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants