Skip to content

Commit df9f904

Browse files
authored
Merge pull request #300848 from ggailey777/fixup
[Functions][Java][SDK types] Initial draft from Ahmed's content
2 parents 97a0eb8 + 7ab3867 commit df9f904

File tree

4 files changed

+178
-12
lines changed

4 files changed

+178
-12
lines changed

articles/azure-functions/functions-app-settings.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: App settings reference for Azure Functions
33
description: Reference documentation for the Azure Functions app settings or environment variables used to configure functions apps.
44
ms.topic: conceptual
55
ms.custom: devx-track-extended-java, devx-track-python, ignite-2023, build-2024, linux-related-content
6-
ms.date: 07/11/2024
6+
ms.date: 06/04/2025
77
---
88

99
# App settings reference for Azure Functions
@@ -501,6 +501,18 @@ This setting enables the Python worker to use shared memory to improve throughpu
501501

502502
With this setting enabled, you can use the [DOCKER_SHM_SIZE](#docker_shm_size) setting to set the shared memory size. To learn more, see [Shared memory](functions-reference-python.md#shared-memory).
503503

504+
## JAVA_ENABLE_SDK_TYPES
505+
506+
Enables your function app to use native Azure SDK types in bindings.
507+
508+
[!INCLUDE [functions-java-sdk-types-preview-note](../../includes/functions-java-sdk-types-preview-note.md)]
509+
510+
|Key|Sample value|
511+
|---|------------|
512+
|JAVA_ENABLE_SDK_TYPES|`true`|
513+
514+
For more information, see [SDK types](functions-reference-java.md#sdk-types) in the Java reference article
515+
504516
## JAVA_OPTS
505517

506518
Used to customize the Java virtual machine (JVM) used to run your Java functions when running on a [Premium plan](./functions-premium-plan.md) or [Dedicated plan](./dedicated-plan.md). When running on a Consumption plan, instead use `languageWorkers__java__arguments`. For more information, see [Customize JVM](functions-reference-java.md#customize-jvm).

articles/azure-functions/functions-bindings-storage-blob-trigger.md

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Azure Blob storage trigger for Azure Functions
33
description: Learn how to use Azure Function to run your custom code based on changes in an Azure Blob storage container.
44
ms.topic: reference
5-
ms.date: 05/14/2024
5+
ms.date: 05/14/2025
66
ms.devlang: csharp
77
# ms.devlang: csharp, java, javascript, powershell, python
88
ms.custom:
@@ -68,7 +68,7 @@ For more information about the `BlobTrigger` attribute, see [Attributes](#attrib
6868
::: zone-end
6969
::: zone pivot="programming-language-java"
7070

71-
This function writes a log when a blob is added or updated in the `myblob` container.
71+
This function uses a byte array to write a log when a blob is added or updated in the `myblob` container.
7272

7373
```java
7474
@FunctionName("blobprocessor")
@@ -84,6 +84,57 @@ public void run(
8484
}
8585
```
8686

87+
This [SDK types example](./functions-reference-java.md#sdk-types) uses `BlobClient` to access properties of the blob.
88+
89+
```java
90+
@FunctionName("processBlob")
91+
public void run(
92+
@BlobTrigger(
93+
name = "content",
94+
path = "images/{name}",
95+
connection = "AzureWebJobsStorage") BlobClient blob,
96+
@BindingName("name") String file,
97+
ExecutionContext ctx)
98+
{
99+
ctx.getLogger().info("Size = " + blob.getProperties().getBlobSize());
100+
}
101+
```
102+
103+
This [SDK types example](./functions-reference-java.md#sdk-types) uses `BlobContainerClient` to access info about blobs in the container that triggered the function.
104+
105+
```java
106+
@FunctionName("containerOps")
107+
public void run(
108+
@BlobTrigger(
109+
name = "content",
110+
path = "images/{name}",
111+
connection = "AzureWebJobsStorage") BlobContainerClient container,
112+
ExecutionContext ctx)
113+
{
114+
container.listBlobs()
115+
.forEach(b -> ctx.getLogger().info(b.getName()));
116+
}
117+
```
118+
119+
This [SDK types example](./functions-reference-java.md#sdk-types) uses `BlobClient` to get information from the input binding about the blob that triggered the execution.
120+
121+
```java
122+
@FunctionName("checkAgainstInputBlob")
123+
public void run(
124+
@BlobInput(
125+
name = "inputBlob",
126+
path = "inputContainer/input.txt") BlobClient inputBlob,
127+
@BlobTrigger(
128+
name = "content",
129+
path = "images/{name}",
130+
connection = "AzureWebJobsStorage",
131+
dataType = "string") String triggerBlob,
132+
ExecutionContext ctx)
133+
{
134+
ctx.getLogger().info("Size = " + inputBlob.getProperties().getBlobSize());
135+
}
136+
```
137+
87138
::: zone-end
88139
::: zone pivot="programming-language-typescript"
89140

@@ -444,7 +495,8 @@ If you get an error message when trying to bind to one of the Storage SDK types,
444495
::: zone-end
445496

446497
::: zone pivot="programming-language-java"
447-
The `@BlobTrigger` attribute is used to give you access to the blob that triggered the function. Refer to the [trigger example](#example) for details.
498+
499+
[!INCLUDE [functions-java-sdk-types-preview-note](../../includes/functions-java-sdk-types-preview-note.md)]
448500
::: zone-end
449501
::: zone pivot="programming-language-javascript,programming-language-typescript"
450502
# [Model v4](#tab/nodejs-v4)

articles/azure-functions/functions-reference-java.md

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Java developer reference for Azure Functions
33
description: Understand how to develop functions with Java.
44
ms.topic: conceptual
5-
ms.date: 09/14/2018
5+
ms.date: 06/04/2025
66
ms.devlang: java
77
ms.custom: devx-track-java, devx-track-extended-java, devx-track-azurecli
88
---
@@ -142,7 +142,7 @@ Here's the generated corresponding `function.json` by the [azure-functions-maven
142142

143143
## Java versions
144144

145-
The version of Java on which your app runs in Azure is specified in the pom.xml file. The Maven archetype currently generates a pom.xml for Java 8, which you can change before publishing. The Java version in pom.xml should match the version on which you've locally developed and tested your app.
145+
The version of Java on which your app runs in Azure is specified in the pom.xml file. The Maven archetype currently generates a pom.xml for Java 8, which you can change before publishing. The Java version in pom.xml should match the version of Java on which you develop and test your app locally.
146146

147147
### Supported versions
148148

@@ -158,7 +158,7 @@ Unless you specify a Java version for your deployment, the Maven archetype defau
158158

159159
### Specify the deployment version
160160

161-
You can control the version of Java targeted by the Maven archetype by using the `-DjavaVersion` parameter. The value of this parameter can be either `8`, `11`, `17` or `21`.
161+
You can control the version of Java targeted by the Maven archetype by using the `-DjavaVersion` parameter. This parameter must match [supported Java versions](supported-languages.md?pivots=programming-language-java#languages-by-runtime-version).
162162

163163
The Maven archetype generates a pom.xml that targets the specified Java version. The following elements in pom.xml indicate the Java version to use:
164164

@@ -269,7 +269,9 @@ The `com.microsoft.azure.functions:azure-functions-java-library` dependency is p
269269

270270
## Data type support
271271

272-
You can use Plain old Java objects (POJOs), types defined in `azure-functions-java-library`, or primitive data types such as String and Integer to bind to input or output bindings.
272+
You can use plain-old Java objects (POJOs), types defined in `azure-functions-java-library`, or primitive data types such as `String` and `Integer` to bind to input or output bindings.
273+
274+
[!INCLUDE [functions-java-sdk-types-preview-note](../../includes/functions-java-sdk-types-preview-note.md)]
273275

274276
### POJOs
275277

@@ -293,6 +295,96 @@ Bind binary inputs or outputs to `byte[]`, by setting the `dataType` field in yo
293295

294296
If you expect null values, use `Optional<T>`.
295297

298+
### <a name="sdk-types"></a>SDK types (preview)
299+
300+
You can currently use these Blob Storage SDK types in your bindings: `BlobClient` and `BlobContainerClient`.
301+
<!--- replace when more than one extension...
302+
+ Blob Storage SDK: `BlobClient` and `BlobContainerClient`
303+
-->
304+
With SDK types support enabled, your functions can use Azure SDK client types to access blobs as streams directly from storage, which provides these benefits over POJOs or binary types:
305+
306+
+ Lower latency
307+
+ Reduced memory requirements
308+
+ Removes request-based size limits (uses service defaults)
309+
+ Provides access to the full SDK surface: metadata, ACLs, legal holds, and other SDK-specific data.
310+
311+
#### Requirements
312+
313+
* Set the [`JAVA_ENABLE_SDK_TYPES`](./functions-app-settings.md#java_enable_sdk_types) app setting to `true` to enable SDK types.
314+
* `azure-functions-maven-plugin` (or Gradle plug-in) version `1.38.0` or a higher version.
315+
316+
#### Examples
317+
318+
Blob trigger that uses `BlobClient` to access properties of the blob.
319+
320+
```java
321+
@FunctionName("processBlob")
322+
public void run(
323+
@BlobTrigger(
324+
name = "content",
325+
path = "images/{name}",
326+
connection = "AzureWebJobsStorage") BlobClient blob,
327+
@BindingName("name") String file,
328+
ExecutionContext ctx)
329+
{
330+
ctx.getLogger().info("Size = " + blob.getProperties().getBlobSize());
331+
}
332+
```
333+
334+
Blob trigger that uses `BlobContainerClient` to access info about blobs in the container.
335+
336+
```java
337+
@FunctionName("containerOps")
338+
public void run(
339+
@BlobTrigger(
340+
name = "content",
341+
path = "images/{name}",
342+
connection = "AzureWebJobsStorage") BlobContainerClient container,
343+
ExecutionContext ctx)
344+
{
345+
container.listBlobs()
346+
.forEach(b -> ctx.getLogger().info(b.getName()));
347+
}
348+
```
349+
350+
Blob input binding that uses `BlobClient` to get information about the blob that triggered the execution.
351+
352+
```java
353+
@FunctionName("checkAgainstInputBlob")
354+
public void run(
355+
@BlobInput(
356+
name = "inputBlob",
357+
path = "inputContainer/input.txt") BlobClient inputBlob,
358+
@BlobTrigger(
359+
name = "content",
360+
path = "images/{name}",
361+
connection = "AzureWebJobsStorage",
362+
dataType = "string") String triggerBlob,
363+
ExecutionContext ctx)
364+
{
365+
ctx.getLogger().info("Size = " + inputBlob.getProperties().getBlobSize());
366+
}
367+
```
368+
369+
#### Considerations
370+
371+
+ The `dataType` setting on `@BlobTrigger` is ignored when binding to an SDK type.
372+
+ Currently, only one SDK type can be used at a time in a given function definition. When a function has both a Blog trigger or input binding and a Blob output binding, one binding can use an SDK type (such as `BlobClient`) and the others must use a native type or POJO.
373+
+ You can use managed identities with SDK types.
374+
375+
#### Troubleshooting
376+
377+
These are potential errors that might occur when using SDK types:
378+
379+
| Exception | Meaning |
380+
| ----- | ----- |
381+
| `SdkAnalysisException` | Build plug-in couldn’t create metadata. This might be due to duplicate SDK-types in a single function definition, an unsupported parameter type, or some other misconfiguration. |
382+
| `SdkRegistryException` | Runtime doesn’t recognize the stored FQCN, which can be caused by mismatched library versions. |
383+
| `SdkHydrationException` | Middleware failed to build the SDK client, which can occur due to missing environment variables, reflection errors, credential failures, and similar runtime issues. |
384+
| `SdkTypeCreationException` | Factory couldn’t turn metadata into the final SDK type, which is usually caused by a casting issues. |
385+
386+
Check the inner message for more details about the exact cause. Most SDK types issues are caused by misspelled environment variable names or missing dependencies.
387+
296388
## Bindings
297389

298390
Input and output bindings provide a declarative way to connect to data from within your code. A function can have multiple input and output bindings.
@@ -415,7 +507,7 @@ You invoke this function on an `HttpRequest` object. It writes multiple values t
415507

416508
## HttpRequestMessage and HttpResponseMessage
417509

418-
These are defined in `azure-functions-java-library`. They're helper types to work with HttpTrigger functions.
510+
These helper types, which are designed to work with HTTP Trigger functions, are defined in `azure-functions-java-library`:
419511

420512
| Specialized type | Target | Typical usage |
421513
| --------------------- | :-----------------: | ------------------------------ |
@@ -465,7 +557,7 @@ In the preceding example, the `queryValue` is bound to the query string paramete
465557
466558
## Execution context
467559

468-
`ExecutionContext`, defined in the `azure-functions-java-library`, contains helper methods to communicate with the functions runtime. For more information, see the [ExecutionContext reference article](/java/api/com.microsoft.azure.functions.executioncontext).
560+
`ExecutionContext`, defined in the `azure-functions-java-library`, contains helper methods that are used to communicate with the functions runtime. For more information, see the [ExecutionContext reference article](/java/api/com.microsoft.azure.functions.executioncontext).
469561

470562
### Logger
471563

@@ -532,7 +624,7 @@ To download the log files as a single ZIP file by using the Azure CLI, open a ne
532624
az webapp log download --resource-group resourcegroupname --name functionappname
533625
```
534626

535-
You must have enabled file system logging in the Azure portal or the Azure CLI before running this command.
627+
You must enable file system logging in the Azure portal or the Azure CLI before running this command.
536628

537629
## Environment variables
538630

@@ -552,7 +644,7 @@ public class Function {
552644
```
553645
## Use dependency injection in Java Functions
554646

555-
Azure Functions Java supports the dependency injection (DI) software design pattern, which is a technique to achieve [Inversion of Control (IoC)](/dotnet/architecture/modern-web-apps-azure/architectural-principles#dependency-inversion) between classes and their dependencies. Java Azure Functions provides a hook to integrate with popular Dependency Injection frameworks in your Functions Apps. [Azure Functions Java SPI](https://github.com/Azure/azure-functions-java-additions/tree/dev/azure-functions-java-spi) contains an interface [FunctionInstanceInjector](https://github.com/Azure/azure-functions-java-additions/blob/dev/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java). By implementing this interface, you can return an instance of your function class and your functions will be invoked on this instance. This gives frameworks like [Spring](/azure/developer/java/spring-framework/getting-started-with-spring-cloud-function-in-azure?toc=%2Fazure%2Fazure-functions%2Ftoc.json), [Quarkus](/azure/azure-functions/functions-create-first-quarkus), Google Guice, Dagger, etc. the ability to create the function instance and register it into their IOC container. This means you can use those Dependency Injection frameworks to manage your functions naturally.
647+
Azure Functions Java supports the dependency injection (DI) software design pattern, which is a technique to achieve [Inversion of Control (IoC)](/dotnet/architecture/modern-web-apps-azure/architectural-principles#dependency-inversion) between classes and their dependencies. Java Azure Functions provides a hook to integrate with popular Dependency Injection frameworks in your Functions Apps. [Azure Functions Java SPI](https://github.com/Azure/azure-functions-java-additions/tree/dev/azure-functions-java-spi) contains an interface [FunctionInstanceInjector](https://github.com/Azure/azure-functions-java-additions/blob/dev/azure-functions-java-spi/src/main/java/com/microsoft/azure/functions/spi/inject/FunctionInstanceInjector.java). By implementing this interface, you can return an instance of your function class and your functions are invoked on this instance. This gives frameworks like [Spring](/azure/developer/java/spring-framework/getting-started-with-spring-cloud-function-in-azure?toc=%2Fazure%2Fazure-functions%2Ftoc.json), [Quarkus](/azure/azure-functions/functions-create-first-quarkus), Google Guice, Dagger, etc. the ability to create the function instance and register it into their IOC container. This means you can use those Dependency Injection frameworks to manage your functions naturally.
556648

557649
> [!NOTE]
558650
> Microsoft Azure Functions Java SPI Types ([azure-function-java-spi](https://mvnrepository.com/artifact/com.microsoft.azure.functions/azure-functions-java-spi/1.0.0)) is a package that contains all SPI interfaces for third parties to interact with Microsoft Azure functions runtime.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
author: ggailey777
3+
ms.service: azure-functions
4+
ms.topic: include
5+
ms.date: 06/03/2025
6+
ms.author: glenga
7+
---
8+
9+
>[!NOTE]
10+
>Support for binding to SDK types is currently in preview and limited to the Azure Blob Storage SDK. For more information, see [SDK types](../articles/azure-functions/functions-reference-java.md#sdk-types) in the Java reference article.

0 commit comments

Comments
 (0)