Azure Functions
Since Camel 4.18
Only producer is supported
The azure-functions component enables integration with Azure Functions. Azure Functions is a serverless compute service that enables you to run code on-demand without having to explicitly provision or manage infrastructure.
This component supports:
-
Invoking HTTP-triggered Azure Functions
-
Managing Azure Function Apps (list, create, delete, start, stop, restart)
-
Managing function app configuration and tags
Prerequisites
You must have a valid Azure subscription. More information is available at Azure Documentation Portal.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-azure-functions</artifactId>
<version>${camel-version}</version>
</dependency> where ${camel-version} must be replaced by the actual version of Camel.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The Azure Functions component supports 21 options, which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
The component configuration. | FunctionsConfiguration | ||
Connection timeout in milliseconds for HTTP invocation. | 30000 | int | |
HTTP method for function invocation (GET, POST, PUT, DELETE, etc.). | POST | String | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Azure region for creating function app (e.g., eastus, westeurope). | String | ||
The operation to be performed. Enum values:
| invokeFunction | FunctionsOperations | |
Read timeout in milliseconds for HTTP invocation. | 60000 | int | |
Runtime stack (java, node, python, dotnet). | String | ||
Runtime version. | String | ||
Storage account connection string for function app. | String | ||
Autowired An AppServiceManager instance for management operations. | AppServiceManager | ||
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean | |
Azure AD Client ID for service principal authentication. | String | ||
Azure AD Client Secret for service principal authentication. | String | ||
Determines the credential strategy to adopt. Enum values:
| AZURE_IDENTITY | CredentialType | |
The function key for direct HTTP invocation. | String | ||
The host key for the function app (used if function key is not provided). | String | ||
The resource group name containing the function app (required for management operations). | String | ||
The Azure subscription ID (required for management operations). | String | ||
Azure AD Tenant ID. | String | ||
Autowired A TokenCredential instance for Azure AD authentication. | TokenCredential |
Endpoint Options
The Azure Functions endpoint is configured using URI syntax:
azure-functions:functionApp/functionName
With the following path and query parameters:
Query Parameters (19 parameters)
| Name | Description | Default | Type |
|---|---|---|---|
Connection timeout in milliseconds for HTTP invocation. | 30000 | int | |
HTTP method for function invocation (GET, POST, PUT, DELETE, etc.). | POST | String | |
Azure region for creating function app (e.g., eastus, westeurope). | String | ||
The operation to be performed. Enum values:
| invokeFunction | FunctionsOperations | |
Read timeout in milliseconds for HTTP invocation. | 60000 | int | |
Runtime stack (java, node, python, dotnet). | String | ||
Runtime version. | String | ||
Storage account connection string for function app. | String | ||
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Autowired An AppServiceManager instance for management operations. | AppServiceManager | ||
Azure AD Client ID for service principal authentication. | String | ||
Azure AD Client Secret for service principal authentication. | String | ||
Determines the credential strategy to adopt. Enum values:
| AZURE_IDENTITY | CredentialType | |
The function key for direct HTTP invocation. | String | ||
The host key for the function app (used if function key is not provided). | String | ||
The resource group name containing the function app (required for management operations). | String | ||
The Azure subscription ID (required for management operations). | String | ||
Azure AD Tenant ID. | String | ||
Autowired A TokenCredential instance for Azure AD authentication. | TokenCredential |
Message Headers
The Azure Functions component supports 18 message header(s), which is/are listed below:
| Name | Description | Default | Type |
|---|---|---|---|
CamelAzureFunctionsOperation (producer) Constant: | The operation to perform. Overrides the operation in the endpoint. Enum values:
| FunctionsOperations | |
CamelAzureFunctionsFunctionApp (producer) Constant: | The function app name. | String | |
CamelAzureFunctionsFunctionName (producer) Constant: | The function name within the app. | String | |
CamelAzureFunctionsResourceGroup (producer) Constant: | The resource group name. | String | |
CamelAzureFunctionsHttpMethod (producer) Constant: | The HTTP method for function invocation (GET, POST, PUT, DELETE, etc.). | String | |
CamelAzureFunctionsHttpHeaders (producer) Constant: | Custom HTTP headers for function invocation. | Map | |
CamelAzureFunctionsStatusCode (producer) Constant: | The HTTP status code from the response. | Integer | |
CamelAzureFunctionsResponseHeaders (producer) Constant: | The response headers from function invocation. | Map | |
CamelAzureFunctionsFunctionAppState (producer) Constant: | The function app state (Running, Stopped, etc.). | String | |
CamelAzureFunctionsResourceId (producer) Constant: | The function app resource ID. | String | |
CamelAzureFunctionsDefaultHostname (producer) Constant: | The default hostname of the function app. | String | |
CamelAzureFunctionsAppSettings (producer) Constant: | App settings to update (for updateFunctionAppConfiguration). | Map | |
CamelAzureFunctionsResourceTags (producer) Constant: | Tags to apply to the resource (for tagResource). | Map | |
CamelAzureFunctionsTagKeys (producer) Constant: | Tag keys to remove from the resource (for untagResource). | List | |
CamelAzureFunctionsLocation (producer) Constant: | Azure region for creating the function app (e.g., eastus, westeurope). | String | |
CamelAzureFunctionsRuntime (producer) Constant: | Runtime stack for the function app (java, node, python, dotnet). | String | |
CamelAzureFunctionsRuntimeVersion (producer) Constant: | Runtime version for the function app. | String | |
CamelAzureFunctionsStorageConnectionString (producer) Constant: | Storage account connection string for the function app. | String |
URI Format
azure-functions:functionApp[/functionName] Where:
-
functionAppis the name of your Azure Function App -
functionNameis the name of the function within the app (required forinvokeFunctionoperation)
Usage
Authentication Information
There are three different Credential Types: AZURE_IDENTITY, FUNCTION_KEY, and TOKEN_CREDENTIAL.
AZURE_IDENTITY (default):
This will use com.azure.identity.DefaultAzureCredentialBuilder().build() instance. This follows the Default Azure Credential Chain which tries multiple authentication methods:
-
Environment variables
-
Managed Identity
-
Azure CLI
-
Visual Studio Code
-
IntelliJ IDEA
See the documentation here about Azure AD authentication.
FUNCTION_KEY:
For invoking HTTP-triggered functions, you can use function keys or host keys:
from("direct:invoke")
.to("azure-functions:myFunctionApp/myFunction?credentialType=FUNCTION_KEY&functionKey=your-function-key"); TOKEN_CREDENTIAL:
Provide an implementation of com.azure.core.credential.TokenCredential into the Camel Registry:
from("direct:invoke")
.to("azure-functions:myFunctionApp/myFunction?credentialType=TOKEN_CREDENTIAL&tokenCredential=#myCredential"); Service Principal Authentication
For service principal authentication, provide the client credentials:
from("direct:manage")
.to("azure-functions:myFunctionApp?operation=listFunctionApps"
+ "&subscriptionId=your-subscription-id"
+ "&resourceGroup=your-resource-group"
+ "&clientId=your-client-id"
+ "&clientSecret=your-client-secret"
+ "&tenantId=your-tenant-id"); Operations
The component supports the following operations:
Function Invocation
| Operation | Description |
|---|---|
| Invokes an HTTP-triggered Azure Function (default operation) |
Function App Management
| Operation | Description |
|---|---|
| List all function apps in the subscription or resource group |
| Get details of a specific function app |
| Create a new function app |
| Delete a function app |
| Start a stopped function app |
| Stop a running function app |
| Restart a function app |
Function Operations
| Operation | Description |
|---|---|
| List all functions within a function app |
| Get details of a specific function |
| Get the master key for the function app |
Examples
Invoke a Function
from("direct:invoke")
.setBody(constant("{\"name\": \"World\"}"))
.to("azure-functions:myFunctionApp/HelloFunction?functionKey=your-key")
.log("Response: ${body}"); List Function Apps
from("direct:list")
.to("azure-functions:myFunctionApp?operation=listFunctionApps"
+ "&subscriptionId=xxx&resourceGroup=myResourceGroup")
.log("Function Apps: ${body}"); Stop a Function App
from("direct:stop")
.to("azure-functions:myFunctionApp?operation=stopFunctionApp"
+ "&subscriptionId=xxx&resourceGroup=myResourceGroup")
.log("Function App stopped"); Update Configuration
from("direct:updateConfig")
.setHeader("CamelAzureFunctionsAppSettings", constant(Map.of("MY_SETTING", "value")))
.to("azure-functions:myFunctionApp?operation=updateFunctionAppConfiguration"
+ "&subscriptionId=xxx&resourceGroup=myResourceGroup")
.log("Configuration updated: ${body}"); Create a Function App
from("direct:create")
.to("azure-functions:newFunctionApp?operation=createFunctionApp"
+ "&subscriptionId=xxx"
+ "&resourceGroup=myResourceGroup"
+ "&location=eastus"
+ "&runtime=java"
+ "&storageAccountConnectionString=DefaultEndpointsProtocol=https;...")
.log("Created function app: ${header.CamelAzureFunctionsResourceId}"); Spring Boot Auto-Configuration
When using azure-functions with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-azure-functions-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency> The component supports 22 options, which are listed below.