Skip to content

moarychan/issue-azure-storage-native

 
 

Repository files navigation

Using Spring Native with Spring Cloud Azure Storage Blob Starter

This code sample demonstrates how to read and write files with the Spring Resource abstraction for Azure Storage using the Spring Cloud Azure storage starter, and build the native executable with Spring Native.

What You Will Build

You will build an application that use Spring Resource abstraction to read and write data with Azure Storage Blob.

What You Need

Setup Azure Storage Emulator

  1. Starter the docker service.
  2. Run the command to start the Azurite with Docker:
docker run -p 10000:10000 mcr.microsoft.com/azure-storage/azurite azurite-blob --blobHost 0.0.0.0
  1. Download Azure Storage Explorer and install.
  2. Configure Azure Storage Explorer:
    1. Connect to Azure Storage. img.png
    2. Configure authentication, select Local storage emulator, and use these default values; img_1.png
    3. Select Next and Connect to finish the configuration, then create a container blobcontainer for testing. img_2.png

Run Locally

Run the sample based on Spring Native

There are two main ways to build a Spring Boot native application.

Run with Buildpacks

  • System Requirements

Docker should be installed, see System Requirements for more details.

  • Build the native application

Run mvn -Pbuildpack package spring-boot:build-image, see Build the native application for more details.

mvn -Pbuildpack package spring-boot:build-image
  • Run the native application

Run docker run --rm -p 8080:8080 issue-azure-storage-native:0.0.1-SNAPSHOT, see Run the native application for more details.

docker run --rm -p 8080:8080 issue-azure-storage-native:0.0.1-SNAPSHOT

Run with Native Build Tools

  • System Requirements

GraalVM native-image compiler should be installed, see System Requirements for more details. If using the Windows platform, you need to install Visual Studio Build Tools, please use VS BuildTools 16.9.

  • Build the native application

Run mvn -Pnative -DskipTests package command using x64 Native Tools Command Prompt, see Build the native application for more details.

mvn -Pnative -DskipTests package

This step will encounter the following exception:

java.lang.SecurityException: class "com.azure.spring.cloud.autoconfigure.compatibility.ContextBootstrapInitializer"'s signer information does not match signer information of other classes in the same package 

If the build is successful, continue with the following content.

  • Run the native application

Run target\issue-azure-storage-native, see Run the native application for more details.

target\issue-azure-storage-native

Verify This Sample

  1. Check out the following console log:

    StorageApplication data initialization begin ... Write data to container=blobcontainer, filePath=azure-blob://blobcontainer/fileName-*.txt Downloaded data from the azure storage blob resource: data-* Get the data content through this address 'curl -XGET http://localhost:8080/blob/fileName-*.txt'. StorageApplication data initialization end ... 
  2. [Optional] Write and read a file.
    2.1 Send a POST request to update file contents.

    curl http://localhost:8080/blob/file1.txt -d "new message" -H "Content-Type: text/plain"

    2.2 Verify by sending a GET request.

    curl -XGET http://localhost:8080/blob/file1.txt
  3. [Optional] Using AzureStorageBlobProtocolResolver to get Azure Storage Blob resources with file pattern.

    curl -XGET http://localhost:8080/blob

    Verify in app's log that a similar messages was posted:

    1 resources founded with pattern:*.txt

Clean Up Resources

After running the sample, if you don't want to run the sample, remember to destroy the Azure resources you created to avoid unnecessary billing.

The terraform destroy command terminates resources managed by your Terraform project.
To destroy the resources you created.

Run with Bash

terraform -chdir=./terraform destroy -auto-approve

Run with Native Tools Command Prompt

terraform -chdir=terraform destroy -auto-approve

About

Demo issue for Spring Cloud Azure Native Support

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published