Important
|
For a general information about building and deploying Azure Functions with Spring Cloud Function, consult the Azure Adapter documentation.
|
The Blob storage trigger starts a function when a new or updated blob is detected. The blob contents are provided as input to the function.
The Blob storage binding is part of an extension bundle, specified in your host.json file.
For local Azure Storage development you need Azurite emulator. For the emulator you can run a docker container (see below) or use the Visual-Studio-Code extension.
Here is how to start the Azure emulator
as docker container:
docker run --name azurite --rm -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
Use the script below to run the function locally.
./mvnw azure-functions:run
Use the Azure Storage Explorer to access the Emulator Storage Account.
Under the Blob Containers
create 3 new containers: test-trigger
, test-input
, test-output
.
Then upload the src/test/resource/sample.txt
file into the test-input
and the test-trigger
folders in this order.
The appearance of the sample.txt
file in the test-trigger
folder triggers the blobTest
function handler, that would look up for a file with the same name (because we used the {name}
convention in the @BlobInput path) from the test-input
folder.
Later is passed through the auto-wired uppercase
service and the result is saved in the test-output
folder.
Verify that the newly created file in test-output
is in capitalized letters.
Make sure you are logged in your Azure account.
az login
then build and deploy
./mvnw clean package
./mvnw azure-functions:deploy
Run the function in debug mode.
./mvnw azure-functions:run -DenableDebug
Alternatively and the JAVA_OPTS
value to your local.settings.json
like this:
{
"IsEncrypted": false,
"Values": {
...
"FUNCTIONS_WORKER_RUNTIME": "java",
"JAVA_OPTS": "-Djava.net.preferIPv4Stack=true -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=127.0.0.1:5005"
}
}
For VSCode remote debug use configuration like this:
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Attach to Remote Program",
"request": "attach",
"hostName": "localhost",
"port": "5005"
},
...
]
}