Azure Storage Blob - Consumer Examples

Consumer Examples

To consume a blob into a file using the file component, this can be done like this:

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/container1?blobName=hello.txt&accountName=yourAccountName&accessKey=yourAccessKey")
    .to("file://blobdirectory");
<route>
    <from uri="azure-storage-blob://camelazure/container1?blobName=hello.txt&amp;accountName=yourAccountName&amp;accessKey=yourAccessKey"/>
    <to uri="file://blobdirectory"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/container1
      parameters:
        blobName: hello.txt
        accountName: yourAccountName
        accessKey: yourAccessKey
    steps:
      - to:
          uri: file://blobdirectory

However, you can also write to file directly without using the file component, you will need to specify fileDir folder path to save your blob in your machine.

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/container1?blobName=hello.txt&accountName=yourAccountName&accessKey=yourAccessKey&fileDir=/var/to/awesome/dir")
    .to("mock:results");
<route>
    <from uri="azure-storage-blob://camelazure/container1?blobName=hello.txt&amp;accountName=yourAccountName&amp;accessKey=yourAccessKey&amp;fileDir=/var/to/awesome/dir"/>
    <to uri="mock:results"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/container1
      parameters:
        blobName: hello.txt
        accountName: yourAccountName
        accessKey: yourAccessKey
        fileDir: /var/to/awesome/dir
    steps:
      - to:
          uri: mock:results

Also, the component supports batch consumer, hence you can consume multiple blobs with only specifying the container name, the consumer will return multiple exchanges depending on the number of the blobs in the container. Example:

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/container1?accountName=yourAccountName&accessKey=yourAccessKey&fileDir=/var/to/awesome/dir")
    .to("mock:results");
<route>
    <from uri="azure-storage-blob://camelazure/container1?accountName=yourAccountName&amp;accessKey=yourAccessKey&amp;fileDir=/var/to/awesome/dir"/>
    <to uri="mock:results"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/container1
      parameters:
        accountName: yourAccountName
        accessKey: yourAccessKey
        fileDir: /var/to/awesome/dir
    steps:
      - to:
          uri: mock:results

Delete After Read

The consumer supports automatic deletion of blobs after they have been successfully processed. This is useful when you want to ensure that blobs are only processed once.

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/container1?deleteAfterRead=true&accessKey=RAW(yourAccessKey)")
    .log("Processing blob: ${header.CamelAzureStorageBlobBlobName}")
    .to("direct:processBlob");
<route>
  <from uri="azure-storage-blob://camelazure/container1?deleteAfterRead=true&amp;accessKey=RAW(yourAccessKey)"/>
  <log message="Processing blob: ${header.CamelAzureStorageBlobBlobName}"/>
  <to uri="direct:processBlob"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/container1
      parameters:
        deleteAfterRead: true
        accessKey: "RAW(yourAccessKey)"
      steps:
        - log:
            message: "Processing blob: ${header.CamelAzureStorageBlobBlobName}"
        - to:
            uri: direct:processBlob
The delete operation is only performed if the Exchange is successfully committed. If processing fails or a rollback occurs, the blob will not be deleted and can be reprocessed on the next poll.
When deleteAfterRead is set to false (the default), the same blobs will be retrieved repeatedly in subsequent polls. In this case, you should use the Idempotent Consumer EIP to filter out duplicates based on the CamelAzureStorageBlobBlobName header.

Move After Read

The consumer can move blobs to a different container after successful processing. This is useful for archiving processed blobs or implementing a processing pipeline across containers.

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/incoming?moveAfterRead=true&destinationContainer=archive&accessKey=RAW(yourAccessKey)")
    .log("Processing blob: ${header.CamelAzureStorageBlobBlobName}")
    .to("direct:processBlob");
<route>
  <from uri="azure-storage-blob://camelazure/incoming?moveAfterRead=true&amp;destinationContainer=archive&amp;accessKey=RAW(yourAccessKey)"/>
  <log message="Processing blob: ${header.CamelAzureStorageBlobBlobName}"/>
  <to uri="direct:processBlob"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/incoming
      parameters:
        moveAfterRead: true
        destinationContainer: archive
        accessKey: "RAW(yourAccessKey)"
      steps:
        - log:
            message: "Processing blob: ${header.CamelAzureStorageBlobBlobName}"
        - to:
            uri: direct:processBlob

You can also customize the destination blob name by adding a prefix and/or suffix:

  • Java

  • XML

  • YAML

from("azure-storage-blob://camelazure/source?moveAfterRead=true&destinationContainer=archive&prefix=incoming/&removePrefixOnMove=true&destinationBlobPrefix=processed/&destinationBlobSuffix=.done&accessKey=RAW(yourAccessKey)")
    .log("Processing: ${header.CamelAzureStorageBlobBlobName}")
    .to("direct:processBlob");
<route>
  <from uri="azure-storage-blob://camelazure/source?moveAfterRead=true&amp;destinationContainer=archive&amp;prefix=incoming/&amp;removePrefixOnMove=true&amp;destinationBlobPrefix=processed/&amp;destinationBlobSuffix=.done&amp;accessKey=RAW(yourAccessKey)"/>
  <log message="Processing: ${header.CamelAzureStorageBlobBlobName}"/>
  <to uri="direct:processBlob"/>
</route>
- route:
    from:
      uri: azure-storage-blob://camelazure/source
      parameters:
        moveAfterRead: true
        destinationContainer: archive
        prefix: "incoming/"
        removePrefixOnMove: true
        destinationBlobPrefix: "processed/"
        destinationBlobSuffix: ".done"
        accessKey: "RAW(yourAccessKey)"
      steps:
        - log:
            message: "Processing: ${header.CamelAzureStorageBlobBlobName}"
        - to:
            uri: direct:processBlob

The move operation works as follows:

  1. The blob is copied to the destination container with the new name

  2. The original blob is deleted from the source container

  3. Both operations only occur after the Exchange is successfully committed

The following options control the move behavior:

Option Description

moveAfterRead

Enable moving blobs after successful processing

destinationContainer

Target container for moved blobs (required when moveAfterRead=true)

destinationBlobPrefix

Prefix to add to the blob name in the destination

destinationBlobSuffix

Suffix to add to the blob name in the destination

removePrefixOnMove

Remove the source prefix from the blob name before adding destination prefix