Search in sources :

Example 1 with BlobContainerClientBuilder

use of com.azure.storage.blob.BlobContainerClientBuilder in project ApplicationInsights-Java by microsoft.

the class ServiceProfilerUploader method uploadToSasLink.

/**
 * Upload the given file to a blob storage defined by a sas link.
 */
private Mono<Response<BlockBlobItem>> uploadToSasLink(BlobAccessPass uploadPass, UploadContext uploadContext, File file) {
    try {
        URL sasUrl = new URL(uploadPass.getUriWithSasToken());
        LOGGER.debug("SAS token: {}", uploadPass.getUriWithSasToken());
        BlobUploadFromFileOptions options = createBlockBlobOptions(file, uploadContext);
        BlobContainerAsyncClient blobContainerClient = new BlobContainerClientBuilder().endpoint(sasUrl.toString()).buildAsyncClient();
        BlobAsyncClient blobClient = blobContainerClient.getBlobAsyncClient(uploadPass.getBlobName());
        return blobClient.uploadFromFileWithResponse(options).doFinally((done) -> LOGGER.info("upload done"));
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Malformed url", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BlobContainerAsyncClient(com.azure.storage.blob.BlobContainerAsyncClient) BlobAsyncClient(com.azure.storage.blob.BlobAsyncClient) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder) URL(java.net.URL)

Example 2 with BlobContainerClientBuilder

use of com.azure.storage.blob.BlobContainerClientBuilder in project springboot-samples by joergjo.

the class EventHubWorker method run.

public void run() {
    logger.info("Worker is starting");
    var blobContainerAsyncClient = new BlobContainerClientBuilder().connectionString(storageConnectionString).containerName(containerName).buildAsyncClient();
    Consumer<EventContext> processEvent = eventContext -> {
        logger.info("Processing event: Event Hub name = {}; consumer group name = {}; partition id = {}; sequence number = {}", eventContext.getPartitionContext().getEventHubName(), eventContext.getPartitionContext().getConsumerGroup(), eventContext.getPartitionContext().getPartitionId(), eventContext.getEventData().getSequenceNumber());
        eventContext.updateCheckpoint();
        total.increment();
    };
    Consumer<ErrorContext> processError = errorContext -> {
        logger.error("Error while processing {}, {}, {}, {}", errorContext.getPartitionContext().getEventHubName(), errorContext.getPartitionContext().getConsumerGroup(), errorContext.getPartitionContext().getPartitionId(), errorContext.getThrowable().getMessage());
    };
    eventProcessorClient = new EventProcessorClientBuilder().consumerGroup(consumerGroup).connectionString(eventHubConnectionString, eventHubName).processEvent(processEvent).processError(processError).checkpointStore(new BlobCheckpointStore(blobContainerAsyncClient)).buildEventProcessorClient();
    eventProcessorClient.start();
    logger.info("Worker has started");
}
Also used : EventContext(com.azure.messaging.eventhubs.models.EventContext) Counter(io.micrometer.core.instrument.Counter) Logger(org.slf4j.Logger) EventContext(com.azure.messaging.eventhubs.models.EventContext) LoggerFactory(org.slf4j.LoggerFactory) EventProcessorClient(com.azure.messaging.eventhubs.EventProcessorClient) BlobCheckpointStore(com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore) ErrorContext(com.azure.messaging.eventhubs.models.ErrorContext) Metrics(io.micrometer.core.instrument.Metrics) Consumer(java.util.function.Consumer) Value(org.springframework.beans.factory.annotation.Value) Component(org.springframework.stereotype.Component) DisposableBean(org.springframework.beans.factory.DisposableBean) EventProcessorClientBuilder(com.azure.messaging.eventhubs.EventProcessorClientBuilder) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder) EventProcessorClientBuilder(com.azure.messaging.eventhubs.EventProcessorClientBuilder) BlobCheckpointStore(com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore) ErrorContext(com.azure.messaging.eventhubs.models.ErrorContext) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder)

Example 3 with BlobContainerClientBuilder

use of com.azure.storage.blob.BlobContainerClientBuilder in project document-management-store-app by hmcts.

the class AzureStorageConfiguration method cloudBlobContainer.

@Bean
@ConditionalOnProperty(value = "azure.storage.enabled", havingValue = "true")
BlobContainerClient cloudBlobContainer() throws UnknownHostException {
    String blobAddress = connectionString.contains("azure-storage-emulator-azurite") ? connectionString.replace("azure-storage-emulator-azurite", InetAddress.getByName("azure-storage-emulator-azurite").getHostAddress()) : connectionString;
    final BlobContainerClient client = new BlobContainerClientBuilder().connectionString(blobAddress).containerName(containerReference).buildClient();
    try {
        client.create();
        return client;
    } catch (BlobStorageException e) {
        return client;
    }
}
Also used : BlobContainerClient(com.azure.storage.blob.BlobContainerClient) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder) BlobStorageException(com.azure.storage.blob.models.BlobStorageException) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

BlobContainerClientBuilder (com.azure.storage.blob.BlobContainerClientBuilder)3 EventProcessorClient (com.azure.messaging.eventhubs.EventProcessorClient)1 EventProcessorClientBuilder (com.azure.messaging.eventhubs.EventProcessorClientBuilder)1 BlobCheckpointStore (com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore)1 ErrorContext (com.azure.messaging.eventhubs.models.ErrorContext)1 EventContext (com.azure.messaging.eventhubs.models.EventContext)1 BlobAsyncClient (com.azure.storage.blob.BlobAsyncClient)1 BlobContainerAsyncClient (com.azure.storage.blob.BlobContainerAsyncClient)1 BlobContainerClient (com.azure.storage.blob.BlobContainerClient)1 BlobStorageException (com.azure.storage.blob.models.BlobStorageException)1 BlobUploadFromFileOptions (com.azure.storage.blob.options.BlobUploadFromFileOptions)1 Counter (io.micrometer.core.instrument.Counter)1 Metrics (io.micrometer.core.instrument.Metrics)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Consumer (java.util.function.Consumer)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DisposableBean (org.springframework.beans.factory.DisposableBean)1 Value (org.springframework.beans.factory.annotation.Value)1