Azure Functions

Since Camel 4.19

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, *.yaml files, 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

configuration (producer)

The component configuration.

FunctionsConfiguration

connectionTimeout (producer)

Connection timeout in milliseconds for HTTP invocation.

30000

int

httpMethod (producer)

HTTP method for function invocation (GET, POST, PUT, DELETE, etc.).

POST

String

lazyStartProducer (producer)

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

location (producer)

Azure region for creating function app (e.g., eastus, westeurope).

String

operation (producer)

The operation to be performed.

Enum values:

  • invokeFunction

  • listFunctionApps

  • getFunctionApp

  • createFunctionApp

  • deleteFunctionApp

  • startFunctionApp

  • stopFunctionApp

  • restartFunctionApp

  • listFunctions

  • getFunction

  • getFunctionKeys

  • getFunctionAppConfiguration

  • updateFunctionAppConfiguration

  • listTags

  • tagResource

  • untagResource

invokeFunction

FunctionsOperations

readTimeout (producer)

Read timeout in milliseconds for HTTP invocation.

60000

int

runtime (producer)

Runtime stack (java, node, python, dotnet).

String

runtimeVersion (producer)

Runtime version.

String

storageAccountConnectionString (producer)

Storage account connection string for function app.

String

appServiceManager (advanced)

Autowired An AppServiceManager instance for management operations.

AppServiceManager

autowiredEnabled (advanced)

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

clientId (security)

Azure AD Client ID for service principal authentication.

String

clientSecret (security)

Azure AD Client Secret for service principal authentication.

String

credentialType (security)

Determines the credential strategy to adopt.

Enum values:

  • AZURE_IDENTITY

  • FUNCTION_KEY

  • TOKEN_CREDENTIAL

AZURE_IDENTITY

CredentialType

functionKey (security)

The function key for direct HTTP invocation.

String

hostKey (security)

The host key for the function app (used if function key is not provided).

String

resourceGroup (security)

The resource group name containing the function app (required for management operations).

String

subscriptionId (security)

The Azure subscription ID (required for management operations).

String

tenantId (security)

Azure AD Tenant ID.

String

tokenCredential (security)

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:

Path Parameters (2 parameters)

Name Description Default Type

functionApp (producer)

Required The Azure Function App name.

String

functionName (producer)

The function name within the app (required for invokeFunction operation).

String

Query Parameters (19 parameters)

Name Description Default Type

connectionTimeout (producer)

Connection timeout in milliseconds for HTTP invocation.

30000

int

httpMethod (producer)

HTTP method for function invocation (GET, POST, PUT, DELETE, etc.).

POST

String

location (producer)

Azure region for creating function app (e.g., eastus, westeurope).

String

operation (producer)

The operation to be performed.

Enum values:

  • invokeFunction

  • listFunctionApps

  • getFunctionApp

  • createFunctionApp

  • deleteFunctionApp

  • startFunctionApp

  • stopFunctionApp

  • restartFunctionApp

  • listFunctions

  • getFunction

  • getFunctionKeys

  • getFunctionAppConfiguration

  • updateFunctionAppConfiguration

  • listTags

  • tagResource

  • untagResource

invokeFunction

FunctionsOperations

readTimeout (producer)

Read timeout in milliseconds for HTTP invocation.

60000

int

runtime (producer)

Runtime stack (java, node, python, dotnet).

String

runtimeVersion (producer)

Runtime version.

String

storageAccountConnectionString (producer)

Storage account connection string for function app.

String

lazyStartProducer (producer (advanced))

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

appServiceManager (advanced)

Autowired An AppServiceManager instance for management operations.

AppServiceManager

clientId (security)

Azure AD Client ID for service principal authentication.

String

clientSecret (security)

Azure AD Client Secret for service principal authentication.

String

credentialType (security)

Determines the credential strategy to adopt.

Enum values:

  • AZURE_IDENTITY

  • FUNCTION_KEY

  • TOKEN_CREDENTIAL

AZURE_IDENTITY

CredentialType

functionKey (security)

The function key for direct HTTP invocation.

String

hostKey (security)

The host key for the function app (used if function key is not provided).

String

resourceGroup (security)

The resource group name containing the function app (required for management operations).

String

subscriptionId (security)

The Azure subscription ID (required for management operations).

String

tenantId (security)

Azure AD Tenant ID.

String

tokenCredential (security)

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: OPERATION

The operation to perform. Overrides the operation in the endpoint.

Enum values:

  • invokeFunction

  • listFunctionApps

  • getFunctionApp

  • createFunctionApp

  • deleteFunctionApp

  • startFunctionApp

  • stopFunctionApp

  • restartFunctionApp

  • listFunctions

  • getFunction

  • getFunctionKeys

  • getFunctionAppConfiguration

  • updateFunctionAppConfiguration

  • listTags

  • tagResource

  • untagResource

FunctionsOperations

CamelAzureFunctionsFunctionApp (producer)

Constant: FUNCTION_APP

The function app name.

String

CamelAzureFunctionsFunctionName (producer)

Constant: FUNCTION_NAME

The function name within the app.

String

CamelAzureFunctionsResourceGroup (producer)

Constant: RESOURCE_GROUP

The resource group name.

String

CamelAzureFunctionsHttpMethod (producer)

Constant: HTTP_METHOD

The HTTP method for function invocation (GET, POST, PUT, DELETE, etc.).

String

CamelAzureFunctionsHttpHeaders (producer)

Constant: HTTP_HEADERS

Custom HTTP headers for function invocation.

Map

CamelAzureFunctionsStatusCode (producer)

Constant: STATUS_CODE

The HTTP status code from the response.

Integer

CamelAzureFunctionsResponseHeaders (producer)

Constant: RESPONSE_HEADERS

The response headers from function invocation.

Map

CamelAzureFunctionsFunctionAppState (producer)

Constant: FUNCTION_APP_STATE

The function app state (Running, Stopped, etc.).

String

CamelAzureFunctionsResourceId (producer)

Constant: RESOURCE_ID

The function app resource ID.

String

CamelAzureFunctionsDefaultHostname (producer)

Constant: DEFAULT_HOSTNAME

The default hostname of the function app.

String

CamelAzureFunctionsAppSettings (producer)

Constant: APP_SETTINGS

App settings to update (for updateFunctionAppConfiguration).

Map

CamelAzureFunctionsResourceTags (producer)

Constant: RESOURCE_TAGS

Tags to apply to the resource (for tagResource).

Map

CamelAzureFunctionsTagKeys (producer)

Constant: TAG_KEYS

Tag keys to remove from the resource (for untagResource).

List

CamelAzureFunctionsLocation (producer)

Constant: LOCATION

Azure region for creating the function app (e.g., eastus, westeurope).

String

CamelAzureFunctionsRuntime (producer)

Constant: RUNTIME

Runtime stack for the function app (java, node, python, dotnet).

String

CamelAzureFunctionsRuntimeVersion (producer)

Constant: RUNTIME_VERSION

Runtime version for the function app.

String

CamelAzureFunctionsStorageConnectionString (producer)

Constant: STORAGE_CONNECTION_STRING

Storage account connection string for the function app.

String

URI Format

azure-functions:functionApp[/functionName]

Where:

  • functionApp is the name of your Azure Function App

  • functionName is the name of the function within the app (required for invokeFunction operation)

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:

  • Java

  • XML

  • YAML

from("direct:invoke")
    .to("azure-functions:myFunctionApp/myFunction?credentialType=FUNCTION_KEY&functionKey=your-function-key");
<route>
  <from uri="direct:invoke"/>
  <to uri="azure-functions:myFunctionApp/myFunction?credentialType=FUNCTION_KEY&amp;functionKey=your-function-key"/>
</route>
- route:
    from:
      uri: direct:invoke
      steps:
        - to:
            uri: azure-functions:myFunctionApp/myFunction
            parameters:
              credentialType: FUNCTION_KEY
              functionKey: your-function-key

TOKEN_CREDENTIAL:

Provide an implementation of com.azure.core.credential.TokenCredential into the Camel Registry:

  • Java

  • XML

  • YAML

from("direct:invoke")
    .to("azure-functions:myFunctionApp/myFunction?credentialType=TOKEN_CREDENTIAL&tokenCredential=#myCredential");
<route>
  <from uri="direct:invoke"/>
  <to uri="azure-functions:myFunctionApp/myFunction?credentialType=TOKEN_CREDENTIAL&amp;tokenCredential=#myCredential"/>
</route>
- route:
    from:
      uri: direct:invoke
      steps:
        - to:
            uri: azure-functions:myFunctionApp/myFunction
            parameters:
              credentialType: TOKEN_CREDENTIAL
              tokenCredential: "#myCredential"

Service Principal Authentication

For service principal authentication, provide the client credentials:

  • Java

  • XML

  • YAML

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");
<route>
  <from uri="direct:manage"/>
  <to uri="azure-functions:myFunctionApp?operation=listFunctionApps&amp;subscriptionId=your-subscription-id&amp;resourceGroup=your-resource-group&amp;clientId=your-client-id&amp;clientSecret=your-client-secret&amp;tenantId=your-tenant-id"/>
</route>
- route:
    from:
      uri: direct:manage
      steps:
        - to:
            uri: azure-functions:myFunctionApp
            parameters:
              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

invokeFunction

Invokes an HTTP-triggered Azure Function (default operation)

Function App Management

Operation Description

listFunctionApps

List all function apps in the subscription or resource group

getFunctionApp

Get details of a specific function app

createFunctionApp

Create a new function app

deleteFunctionApp

Delete a function app

startFunctionApp

Start a stopped function app

stopFunctionApp

Stop a running function app

restartFunctionApp

Restart a function app

Function Operations

Operation Description

listFunctions

List all functions within a function app

getFunction

Get details of a specific function

getFunctionKeys

Get the master key for the function app

Configuration Operations

Operation Description

getFunctionAppConfiguration

Get app settings/configuration

updateFunctionAppConfiguration

Update app settings

Tag Operations

Operation Description

listTags

List tags on the function app resource

tagResource

Add tags to the function app

untagResource

Remove tags from the function app

Examples

Invoke a Function

  • Java

  • XML

  • YAML

from("direct:invoke")
    .setBody(constant("{\"name\": \"World\"}"))
    .to("azure-functions:myFunctionApp/HelloFunction?functionKey=your-key")
    .log("Response: ${body}");
<route>
  <from uri="direct:invoke"/>
  <setBody>
    <constant>{"name": "World"}</constant>
  </setBody>
  <to uri="azure-functions:myFunctionApp/HelloFunction?functionKey=your-key"/>
  <log message="Response: ${body}"/>
</route>
- route:
    from:
      uri: direct:invoke
      steps:
        - setBody:
            constant: '{"name": "World"}'
        - to:
            uri: azure-functions:myFunctionApp/HelloFunction
            parameters:
              functionKey: your-key
        - log:
            message: "Response: ${body}"

List Function Apps

  • Java

  • XML

  • YAML

from("direct:list")
    .to("azure-functions:myFunctionApp?operation=listFunctionApps&subscriptionId=xxx&resourceGroup=myResourceGroup")
    .log("Function Apps: ${body}");
<route>
  <from uri="direct:list"/>
  <to uri="azure-functions:myFunctionApp?operation=listFunctionApps&amp;subscriptionId=xxx&amp;resourceGroup=myResourceGroup"/>
  <log message="Function Apps: ${body}"/>
</route>
- route:
    from:
      uri: direct:list
      steps:
        - to:
            uri: azure-functions:myFunctionApp
            parameters:
              operation: listFunctionApps
              subscriptionId: xxx
              resourceGroup: myResourceGroup
        - log:
            message: "Function Apps: ${body}"

Stop a Function App

  • Java

  • XML

  • YAML

from("direct:stop")
    .to("azure-functions:myFunctionApp?operation=stopFunctionApp&subscriptionId=xxx&resourceGroup=myResourceGroup")
    .log("Function App stopped");
<route>
  <from uri="direct:stop"/>
  <to uri="azure-functions:myFunctionApp?operation=stopFunctionApp&amp;subscriptionId=xxx&amp;resourceGroup=myResourceGroup"/>
  <log message="Function App stopped"/>
</route>
- route:
    from:
      uri: direct:stop
      steps:
        - to:
            uri: azure-functions:myFunctionApp
            parameters:
              operation: stopFunctionApp
              subscriptionId: xxx
              resourceGroup: myResourceGroup
        - log:
            message: "Function App stopped"

Update Configuration

Java-only: requires Java Map.of() for app settings
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

  • Java

  • XML

  • YAML

from("direct:create")
    .to("azure-functions:newFunctionApp?operation=createFunctionApp&subscriptionId=xxx&resourceGroup=myResourceGroup&location=eastus&runtime=java&storageAccountConnectionString=RAW(DefaultEndpointsProtocol=https;...)")
    .log("Created function app: ${header.CamelAzureFunctionsResourceId}");
<route>
  <from uri="direct:create"/>
  <to uri="azure-functions:newFunctionApp?operation=createFunctionApp&amp;subscriptionId=xxx&amp;resourceGroup=myResourceGroup&amp;location=eastus&amp;runtime=java&amp;storageAccountConnectionString=RAW(DefaultEndpointsProtocol=https;...)"/>
  <log message="Created function app: ${header.CamelAzureFunctionsResourceId}"/>
</route>
- route:
    from:
      uri: direct:create
      steps:
        - to:
            uri: azure-functions:newFunctionApp
            parameters:
              operation: createFunctionApp
              subscriptionId: xxx
              resourceGroup: myResourceGroup
              location: eastus
              runtime: java
              storageAccountConnectionString: "RAW(DefaultEndpointsProtocol=https;...)"
        - log:
            message: "Created function app: ${header.CamelAzureFunctionsResourceId}"