Package com.azure.storage.blob.batch
Class BlobBatchAsyncClient
java.lang.Object
com.azure.storage.blob.batch.BlobBatchAsyncClient
This class provides a client that contains all operations that apply to Azure Storage Blob batching.
This client offers the ability to delete and set access tier on multiple blobs at once and to submit a BlobBatch
.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncom.azure.core.http.rest.PagedFlux<com.azure.core.http.rest.Response<Void>>
deleteBlobs
(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions) Delete multiple blobs in a single request to the service.Gets aBlobBatch
used to configure a batching operation to send to Azure Storage blobs.com.azure.core.http.rest.PagedFlux<com.azure.core.http.rest.Response<Void>>
setBlobsAccessTier
(List<String> blobUrls, AccessTier accessTier) Set access tier on multiple blobs in a single request to the service.submitBatch
(BlobBatch batch) Submits a batch operation.submitBatchWithResponse
(BlobBatch batch, boolean throwOnAnyFailure) Submits a batch operation.
-
Method Details
-
getBlobBatch
Gets aBlobBatch
used to configure a batching operation to send to Azure Storage blobs.- Returns:
- a new
BlobBatch
instance.
-
submitBatch
Submits a batch operation.If any request in a batch fails this will throw a
BlobStorageException
.Code samples
BlobBatch batch = batchAsyncClient.getBlobBatch(); Response<Void> deleteResponse1 = batch.deleteBlob("container", "blob1"); Response<Void> deleteResponse2 = batch.deleteBlob("container", "blob2", DeleteSnapshotsOptionType.INCLUDE, new BlobRequestConditions().setLeaseId("leaseId")); batchAsyncClient.submitBatch(batch).subscribe(response -> { System.out.println("Batch submission completed successfully."); System.out.printf("Delete operation 1 completed with status code: %d%n", deleteResponse1.getStatusCode()); System.out.printf("Delete operation 2 completed with status code: %d%n", deleteResponse2.getStatusCode()); }, error -> System.err.printf("Batch submission failed. Error message: %s%n", error.getMessage()));
- Parameters:
batch
- Batch to submit.- Returns:
- An empty response indicating that the batch operation has completed.
- Throws:
BlobStorageException
- If the batch request is malformed.BlobBatchStorageException
- If any request in theBlobBatch
failed.
-
submitBatchWithResponse
public Mono<com.azure.core.http.rest.Response<Void>> submitBatchWithResponse(BlobBatch batch, boolean throwOnAnyFailure) Submits a batch operation.If
throwOnAnyFailure
istrue
aBlobStorageException
will be thrown if any request fails.Code samples
BlobBatch batch = batchAsyncClient.getBlobBatch(); Response<Void> deleteResponse1 = batch.deleteBlob("container", "blob1"); Response<Void> deleteResponse2 = batch.deleteBlob("container", "blob2", DeleteSnapshotsOptionType.INCLUDE, new BlobRequestConditions().setLeaseId("leaseId")); batchAsyncClient.submitBatchWithResponse(batch, true).subscribe(response -> { System.out.printf("Batch submission completed with status code: %d%n", response.getStatusCode()); System.out.printf("Delete operation 1 completed with status code: %d%n", deleteResponse1.getStatusCode()); System.out.printf("Delete operation 2 completed with status code: %d%n", deleteResponse2.getStatusCode()); }, error -> System.err.printf("Batch submission failed. Error message: %s%n", error.getMessage()));
- Parameters:
batch
- Batch to submit.throwOnAnyFailure
- Flag to indicate if an exception should be thrown if any request in the batch fails.- Returns:
- A response only containing header and status code information, used to indicate that the batch operation has completed.
- Throws:
BlobStorageException
- If the batch request is malformed.BlobBatchStorageException
- IfthrowOnAnyFailure
istrue
and any request in theBlobBatch
failed.
-
deleteBlobs
public com.azure.core.http.rest.PagedFlux<com.azure.core.http.rest.Response<Void>> deleteBlobs(List<String> blobUrls, DeleteSnapshotsOptionType deleteOptions) Delete multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); batchAsyncClient.deleteBlobs(blobUrls, DeleteSnapshotsOptionType.INCLUDE).subscribe(response -> System.out.printf("Deleting blob with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode()), error -> System.err.printf("Deleting blob failed with exception: %s%n", error.getMessage()));
- Parameters:
blobUrls
- Urls of the blobs to delete. Blob names must be encoded to UTF-8.deleteOptions
- The deletion option for all blobs.- Returns:
- The status of each delete operation.
- Throws:
BlobStorageException
- If the batch request is malformed.BlobBatchStorageException
- If any of the delete operations fail.
-
setBlobsAccessTier
public com.azure.core.http.rest.PagedFlux<com.azure.core.http.rest.Response<Void>> setBlobsAccessTier(List<String> blobUrls, AccessTier accessTier) Set access tier on multiple blobs in a single request to the service.Code samples
List<String> blobUrls = new ArrayList<>(); blobUrls.add(blobClient1.getBlobUrl()); blobUrls.add(blobClient2.getBlobUrl()); blobUrls.add(blobClient3.getBlobUrl()); batchAsyncClient.setBlobsAccessTier(blobUrls, AccessTier.HOT).subscribe(response -> System.out.printf("Setting blob access tier with URL %s completed with status code %d%n", response.getRequest().getUrl(), response.getStatusCode()), error -> System.err.printf("Setting blob access tier failed with exception: %s%n", error.getMessage()));
- Parameters:
blobUrls
- Urls of the blobs to set their access tier. Blob names must be encoded to UTF-8.accessTier
-AccessTier
to set on each blob.- Returns:
- The status of each set tier operation.
- Throws:
BlobStorageException
- If the batch request is malformed.BlobBatchStorageException
- If any of the set tier operations fail.
-