Azure samples version and code adjustments
This commit is contained in:
@@ -9,6 +9,16 @@ The Blob storage binding is part of an https://learn.microsoft.com/en-us/azure/a
|
||||
|
||||
=== Usage
|
||||
|
||||
For local Azure Storage development you need https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio[Azurite emulator].
|
||||
For the emulator you can run a docker container (see below) or use the https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?tabs=visual-studio-code[Visual-Studio-Code extension].
|
||||
|
||||
Here is how to start the `Azure emulator` as docker container:
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
docker run --name azurite --rm -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
|
||||
----
|
||||
|
||||
==== Package Staging folder
|
||||
|
||||
Use the script below to package your staging folder:
|
||||
@@ -27,11 +37,14 @@ Use the script below to run the function locally.
|
||||
./mvnw azure-functions:run
|
||||
----
|
||||
|
||||
NOTE: To run locally on top of `Azure Functions`, and to deploy to your live Azure environment, you will need `Azure Functions Core Tools` installed along with the Azure CLI (see https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-java?tabs=bash%2Cazure-cli%2Cbrowser#configure-your-local-environment[here]).
|
||||
Use the https://azure.microsoft.com/en-us/products/storage/storage-explorer/[Azure Storage Explorer] to access the Emulator Storage Account.
|
||||
|
||||
NOTE: https://github.com/Azure/azure-functions-core-tools[Azure Functions Core Tools] version `4.0.5030` or newer is required!
|
||||
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.
|
||||
|
||||
For some configuration you would need the https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator[Azurite emulator] as well.
|
||||
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.
|
||||
|
||||
|
||||
==== Deploy Azure Functions to Azure Cloud
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.0.7</version>
|
||||
<version>3.1.1</version>
|
||||
<relativePath/>
|
||||
<!-- lookup parent from repository -->
|
||||
</parent>
|
||||
@@ -33,7 +33,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-adapter-azure</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.0.5-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -30,7 +30,7 @@ public class AzureBlobTriggerDemoApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return payload -> payload.toUpperCase();
|
||||
public Function<byte[], byte[]> uppercase() {
|
||||
return payload -> new String(payload).toUpperCase().getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,33 +33,33 @@ import org.springframework.stereotype.Component;
|
||||
/**
|
||||
* Azure Functions with Azure Storage Blob.
|
||||
* https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=java
|
||||
*
|
||||
* The Blob storage binding is part of an extension bundle, which is specified in your host.json project file.
|
||||
*
|
||||
* The Blob storage binding is part of an extension bundle, which is specified in your host.json project file.
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class MyBlobFunction {
|
||||
|
||||
|
||||
@Autowired
|
||||
private Function<String, String> uppercase;
|
||||
private Function<byte[], byte[]> uppercase;
|
||||
|
||||
/**
|
||||
* This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are
|
||||
* provided as input to this function. The location of the blob is provided in the path parameter. Example -
|
||||
* test-triggerinput-java/{name} below
|
||||
* test-trigger/{name} below
|
||||
*/
|
||||
@FunctionName("BlobTrigger")
|
||||
@StorageAccount("AzureWebJobsStorage")
|
||||
public void BlobTriggerToBlobTest(
|
||||
@BlobTrigger(name = "triggerBlob", path = "test-triggerinput-java/{name}", dataType = "binary") byte[] triggerBlob,
|
||||
public void blobTest(
|
||||
@BlobTrigger(name = "triggerBlob", path = "test-trigger/{name}", dataType = "binary") byte[] triggerBlob,
|
||||
@BindingName("name") String fileName,
|
||||
@BlobInput(name = "inputBlob", path = "test-input-java/{name}", dataType = "binary") byte[] inputBlob,
|
||||
@BlobOutput(name = "outputBlob", path = "test-output-java/{name}", dataType = "binary") OutputBinding<byte[]> outputBlob,
|
||||
@BlobInput(name = "inputBlob", path = "test-input/{name}", dataType = "binary") byte[] inputBlob,
|
||||
@BlobOutput(name = "outputBlob", path = "test-output/{name}", dataType = "binary") OutputBinding<byte[]> outputBlob,
|
||||
final ExecutionContext context) {
|
||||
|
||||
context.getLogger().info("Java Blob trigger function BlobTriggerToBlobTest processed a blob.\n Name: "
|
||||
|
||||
context.getLogger().info("Java Blob trigger function blobTest processed a blob.\n Name: "
|
||||
+ fileName + "\n Size: " + triggerBlob.length + " Bytes");
|
||||
outputBlob.setValue(inputBlob);
|
||||
|
||||
outputBlob.setValue(uppercase.apply(inputBlob));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
Authoritarianism begins when we can no longer tell the difference between the true and the appealing.
|
||||
At the same time, the cynic who decides that there is no truth at all is the citizen who welcomes the tyrant.
|
||||
― Timothy Snyder, The Road to Unfreedom
|
||||
Reference in New Issue
Block a user