Use Durable Functions, a feature of Azure Functions, to write stateful functions in a serverless environment. Durable Functions manages state, checkpoints, and restarts in your application.
In this quickstart, you create and test a "hello world" Durable Functions app in Java.
The most basic Durable Functions app has three functions:
Orchestrator function: A workflow that orchestrates other functions.
Activity function: A function that is called by the orchestrator function, performs work, and optionally returns a value.
Client function: A regular function in Azure that starts an orchestrator function. This example uses an HTTP-triggered function.
This quickstart describes different ways to create this "hello world" app. Use the selector at the top of the page to set your preferred approach.
It's important to note that only the Azure Functions v4 extension bundle currently has the necessary support for Durable Functions for Java. Durable Functions for Java is not supported in v3 and early extension bundles. For more information on extension bundles, see the extension bundles documentation.
Durable Functions needs a storage provider to store runtime state. Add a local.settings.json file to your project directory to configure the storage provider. To use Azure Storage as the provider, set the value of AzureWebJobsStorage to the connection string of your Azure Storage account:
At the prompts, provide the following information:
Prompt
Action
groupId
Enter com.function.
artifactId
Enter myDurableFunction.
version
Select 1.0-SNAPSHOT.
package
Enter com.function.
Y
Enter Y and select Enter to confirm.
Now you have a local project that has the three functions that are in a basic Durable Functions app.
Check to ensure that com.microsoft:durabletask-azure-functions is set as a dependency in your pom.xml file.
Configure the back-end storage provider
Durable Functions needs a storage provider to store runtime state. You can set Azure Storage as the storage provider in local.settings.json. Use the connection string of your Azure storage account as the value for AzureWebJobsStorage like in this example:
In Visual Studio Code, select F1 (or select Ctrl/Cmd+Shift+P) to open the command palette. At the prompt (>), enter and then select Azure Functions: Create New Project.
Select Browse. In the Select Folder dialog, go to a folder to use for your project, and then choose Select.
At the prompts, provide the following information:
Prompt
Action
Select a language
Select Java.
Select a version of Java
Select Java 8 or later. Select the Java version that your functions run on in Azure, and one that you verified locally.
Provide a group ID
Enter com.function.
Provide an artifact ID
Enter myDurableFunction.
Provide a version
Enter 1.0-SNAPSHOT.
Provide a package name
Enter com.function.
Provide an app name
Enter myDurableFunction.
Select the build tool for Java project
Select Maven.
Select how you would like to open your project
Select Open in new window.
You now have a project that has an example HTTP function. You can remove this function if you'd like to, because you add the basic functions of a Durable Functions app in the next step.
Add functions to the project
In the command palette, enter and then select Azure Functions: Create Function.
For Change template filter, select All.
At the prompts, provide the following information:
Prompt
Action
Select a template for your function
Select DurableFunctionsOrchestration.
Provide a package name
Enter com.function.
Provide a function name
Enter DurableFunctionsOrchestrator.
In the dialog, choose Select storage account to set up a storage account, and then follow the prompts.
You should now have the three basic functions generated for a Durable Functions app.
Configure pom.xml and host.json
Add the following dependency to your pom.xml file:
Azure Functions Core Tools gives you the capability to run an Azure Functions project on your local development computer.
Napomena
Durable Functions for Java requires Azure Functions Core Tools version 4.0.4915 or later. You can see which version is installed by running the func --version command in the terminal.
If you're using Visual Studio Code, open a new terminal window and run the following commands to build the project:
Bash
mvn clean package
Then, run the durable function:
Bash
mvn azure-functions:run
In the terminal panel, copy the URL endpoint of your HTTP-triggered function.
Use an HTTP test tool to send an HTTP POST request to the URL endpoint.
The response should look similar to the following example:
The response is the HTTP function's initial result. It lets you know that the durable orchestration started successfully. It doesn't yet display the end result of the orchestration. The response includes a few useful URLs. For now, query the status of the orchestration.
Copy the URL value for statusQueryGetUri, paste it in your browser's address bar, and execute the request. Alternatively, you can continue to use the HTTP test tool to issue the GET request.
The request queries the orchestration instance for the status. You should see that the instance finished and that it includes the outputs or results of the durable function, like in this example:
Pridružite se seriji susreta kako biste s kolegama programerima i stručnjacima izgradili skalabilna rješenja umjetne inteligencije temeljena na stvarnim slučajevima upotrebe.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.