├── mvnBuild.bat ├── mvnBuildSkipTests.bat ├── src ├── main │ └── java │ │ └── com │ │ └── microsoft │ │ └── azure │ │ └── functions │ │ ├── package-info.java │ │ ├── annotation │ │ ├── package-info.java │ │ ├── AccessRights.java │ │ ├── Cardinality.java │ │ ├── AuthorizationLevel.java │ │ ├── StorageAccount.java │ │ ├── BindingName.java │ │ ├── HttpOutput.java │ │ ├── CustomBinding.java │ │ ├── FunctionName.java │ │ ├── EventGridTrigger.java │ │ ├── TableOutput.java │ │ ├── TwilioSmsOutput.java │ │ ├── SendGridOutput.java │ │ ├── EventHubOutput.java │ │ ├── ServiceBusTopicOutput.java │ │ ├── QueueTrigger.java │ │ ├── QueueOutput.java │ │ ├── BlobOutput.java │ │ ├── BlobInput.java │ │ ├── BlobTrigger.java │ │ ├── ServiceBusQueueOutput.java │ │ ├── ServiceBusQueueTrigger.java │ │ ├── EventHubTrigger.java │ │ ├── ServiceBusTopicTrigger.java │ │ ├── TableInput.java │ │ ├── TimerTrigger.java │ │ ├── CosmosDBInput.java │ │ ├── CosmosDBOutput.java │ │ ├── CosmosDBTrigger.java │ │ └── HttpTrigger.java │ │ ├── OutputBinding.java │ │ ├── HttpMethod.java │ │ ├── HttpStatusType.java │ │ ├── ExecutionContext.java │ │ ├── HttpStatus.java │ │ ├── HttpResponseMessage.java │ │ └── HttpRequestMessage.java └── test │ └── java │ └── com │ └── microsoft │ └── azure │ └── functions │ ├── HttpStatusTest.java │ └── annotation │ └── BindingTest.java ├── mvnGenerateArchetype.bat ├── CODEOWNERS ├── appveyor.yml ├── .gitignore ├── updateVersions.bat ├── LICENSE ├── pom.xml └── README.md /mvnBuild.bat: -------------------------------------------------------------------------------- 1 | mvn clean install -U -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B -Dgpg.skip -------------------------------------------------------------------------------- /mvnBuildSkipTests.bat: -------------------------------------------------------------------------------- 1 | mvn clean install -Dmaven.javadoc.skip=true -Dmaven.test.skip -U -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | /** 8 | * Root package 9 | */ 10 | 11 | package com.microsoft.azure.functions; 12 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | /** 8 | * Annotations and support classes for use as part of the Java API for Azure Functions. 9 | */ 10 | 11 | package com.microsoft.azure.functions.annotation; 12 | -------------------------------------------------------------------------------- /mvnGenerateArchetype.bat: -------------------------------------------------------------------------------- 1 | set atchetypeVersion=%1 2 | 3 | mvn archetype:generate -DarchetypeCatalog="local" -DarchetypeGroupId="com.microsoft.azure" -DarchetypeArtifactId="azure-functions-archetype" -DarchetypeVersion="%atchetypeVersion%" -DgroupId="com.microsoft" -DartifactId="e2etestproject" -Dversion="1.0-SNAPSHOT" -Dpackage="com.microsoft" -DappRegion="westus" -DresourceGroup="e2etest-java-functions-group" -DappName="e2etest-java-functions" -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B 4 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | # CODEOWNERS is a GitHub standard to specify who is automatically assigned pull requests to review. 2 | # This helps to prevent pull requests from languishing without review. 3 | # GitHub can also be configured to require review from code owners before a pull request can be merged. 4 | 5 | # Further reading is available from the following two URLs: 6 | # https://blog.github.com/2017-07-06-introducing-code-owners/ 7 | # https://help.github.com/articles/about-codeowners/ 8 | 9 | # Default owner for repo 10 | * @pragnagopa -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | 3 | image: Visual Studio 2017 4 | 5 | pull_requests: 6 | do_not_increment_build_number: true 7 | 8 | branches: 9 | only: 10 | - dev 11 | - master 12 | 13 | environment: 14 | matrix: 15 | - JAVA_HOME: C:\Program Files\Java\jdk1.8.0 16 | 17 | install: 18 | - cmd: echo %JAVA_HOME% 19 | - ps: Get-Command mvn 20 | 21 | build_script: 22 | - ps: '& .\build.ps1' 23 | 24 | artifacts: 25 | - path: 'azure-functions-java-library/target/**.jar' 26 | 27 | cache: 28 | - C:\maven\ -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | /.idea/* 25 | /target/* 26 | /bin 27 | /.classpath 28 | /.settings/* 29 | .project 30 | /azure-maven-archetypes/ 31 | /azure-maven-plugins/ 32 | /ciTestDir/* 33 | /target/ 34 | /Azure.Functions.Cli/* 35 | /azure-functions-java-worker/ 36 | -------------------------------------------------------------------------------- /updateVersions.bat: -------------------------------------------------------------------------------- 1 | set libraryVersion=%1 2 | set pluginVersion=%2 3 | echo setting azure.functions.java.library.version to %libraryVersion% 4 | call mvn versions:set-property -Dproperty=azure.functions.java.library.version -DnewVersion=%libraryVersion% -U -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B 5 | IF DEFINED pluginVersion ( 6 | echo setting azure.functions.maven.plugin.version to %pluginVersion% 7 | call mvn versions:set-property -Dproperty=azure.functions.maven.plugin.version -DnewVersion=%pluginVersion% -U -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -B 8 | ) 9 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/AccessRights.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions.annotation; 8 | 9 | /** 10 | * Azure Service Bus permission. 11 | * 12 | * @since 1.0.0 13 | */ 14 | public enum AccessRights { 15 | /** 16 | * Confers the right to manage the topology of the namespace, including creating and deleting entities. 17 | */ 18 | MANAGE, 19 | 20 | /** 21 | * Confers the right to listen (relay) or receive (queue, subscriptions) and all related message handling. 22 | */ 23 | LISTEN 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/Cardinality.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions.annotation; 8 | 9 | /** 10 | *
11 | * Cardinality of the EventHubTrigger input. Choose 'ONE' if the input is a single message or 'Many' 12 | * if the input is an array of messages. 'Many' is the default if unspecified 13 | *
14 | * 15 | * @since 1.0.0 16 | */ 17 | public enum Cardinality { 18 | /** 19 | * To receive a single message, set cardinality to ONE 20 | */ 21 | ONE, 22 | 23 | /** 24 | * To receive events in a batch, set cardinality to MANY. This is the default if omitted. 25 | */ 26 | MANY 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/OutputBinding.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions; 8 | 9 | /** 10 | *This type should be used with the parameter of output bindings.
11 | * 12 | * @since 1.0.0 13 | */ 14 | public interface OutputBindingAzure HTTP authorization level, Determines what keys, if any, need to be present on the request in order to 11 | * invoke the function.
12 | * 13 | * @since 1.0.0 14 | */ 15 | public enum AuthorizationLevel { 16 | /** 17 | * No API key is required. 18 | */ 19 | ANONYMOUS, 20 | 21 | /** 22 | * A function-specific API key is required. This is the default value if none is provided. 23 | */ 24 | FUNCTION, 25 | 26 | /** 27 | * The master key is required. 28 | */ 29 | ADMIN 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/com/microsoft/azure/functions/HttpStatusTest.java: -------------------------------------------------------------------------------- 1 | package com.microsoft.azure.functions; 2 | 3 | import org.junit.*; 4 | 5 | import static junit.framework.TestCase.*; 6 | 7 | /** 8 | * Unit tests that enforce annotation contracts and conventions for Functions 9 | */ 10 | public class HttpStatusTest { 11 | @Test 12 | public void set_custom_httpstatuscode() { 13 | HttpStatusType customHttpStatus = HttpStatusType.custom(209); 14 | assertTrue(customHttpStatus.value() == 209); 15 | } 16 | 17 | @Test 18 | public void set_standard_httpstatuscode() { 19 | HttpStatusType customHttpStatus = HttpStatus.OK; 20 | assertTrue(customHttpStatus.value() == 200); 21 | } 22 | 23 | @Test(expected = IllegalArgumentException.class) 24 | public void set_invalid_httpstatuscode() { 25 | HttpStatusType.custom(-100); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions; 8 | 9 | import java.util.Locale; 10 | 11 | /** 12 | * Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See 13 | * License.txt in the project root for license information. 14 | */ 15 | 16 | public enum HttpMethod { 17 | 18 | GET, HEAD, POST, PUT, DELETE, CONNECT, OPTIONS, TRACE; 19 | 20 | /** 21 | * Converts passed value to upper case to extract valueOf() of this Enum. 22 | * 23 | * @param value of http method in any case 24 | * @return this enum 25 | */ 26 | public static HttpMethod value(String value) { 27 | return HttpMethod.valueOf(value.toUpperCase(Locale.ROOT)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/HttpStatusType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions; 8 | 9 | /** 10 | * Defines an HTTP Status Type 11 | * 12 | * @since 1.0 13 | */ 14 | public interface HttpStatusType { 15 | 16 | public int value(); 17 | 18 | /** 19 | * Creates a custom (non-standard) HTTP Status code. 20 | * @param code for HttpStatusCode 21 | * @return HttpStatusType 22 | */ 23 | public static HttpStatusType custom(final int code) { 24 | if (code <= 0) { 25 | throw new IllegalArgumentException("A positive integer must be provided."); 26 | } 27 | 28 | return new HttpStatusType() { 29 | @Override 30 | public int value() { 31 | return code; 32 | } 33 | }; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/StorageAccount.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions.annotation; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | *Apply this annotation to a method if you have multiple Azure Storage triggers/input/output in that method which 16 | * share the same app setting name of Azure Storage connection string.
17 | * 18 | * @since 1.0.0 19 | */ 20 | @Retention(RetentionPolicy.RUNTIME) 21 | @Target(ElementType.METHOD) 22 | public @interface StorageAccount { 23 | /** 24 | * Defines the app setting name that contains the Azure Storage connection string. 25 | * @return The app setting name of the connection string. 26 | */ 27 | String value(); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/BindingName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions.annotation; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | *16 | * Place this on a parameter whose value would come from Azure Functions runtime. Use this 17 | * annotation when you want to get the value of trigger metadata, or when you defined your own 18 | * bindings in function.json manually. 19 | *
20 | * 21 | * @since 1.0.0 22 | */ 23 | @Target(ElementType.PARAMETER) 24 | @Retention(RetentionPolicy.RUNTIME) 25 | public @interface BindingName { 26 | /** 27 | * Defines the trigger metadata name or binding name defined in function.json. 28 | * 29 | * @return The trigger metadata name or binding name. 30 | */ 31 | String value(); 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/ExecutionContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions; 8 | 9 | import java.util.logging.Logger; 10 | 11 | /** 12 | * The execution context enables interaction with the Azure Functions execution environment. 13 | * 14 | * @since 1.0.0 15 | */ 16 | public interface ExecutionContext { 17 | /** 18 | * Returns the built-in logger, which is integrated with the logging functionality provided in the Azure Functions 19 | * portal, as well as in Azure Application Insights. 20 | * 21 | * @return A Java logger that will see output directed to Azure Portal, as well as any other configured output 22 | * locations. 23 | */ 24 | Logger getLogger(); 25 | 26 | /** 27 | * Returns the invocation ID for the function call. 28 | * @return the invocation ID for the function call. 29 | */ 30 | String getInvocationId(); 31 | 32 | /** 33 | * Returns the function name. 34 | * @return the function name. 35 | */ 36 | String getFunctionName(); 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/microsoft/azure/functions/annotation/HttpOutput.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Microsoft Corporation. All rights reserved. 3 | * Licensed under the MIT License. See License.txt in the project root for 4 | * license information. 5 | */ 6 | 7 | package com.microsoft.azure.functions.annotation; 8 | 9 | import java.lang.annotation.ElementType; 10 | import java.lang.annotation.Retention; 11 | import java.lang.annotation.RetentionPolicy; 12 | import java.lang.annotation.Target; 13 | 14 | /** 15 | *Place this on a parameter whose value would be send back to the user as an HTTP response. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *Defines how Functions runtime should treat the parameter value. Possible values are:
38 | *14 | * Place this on a parameter to define a custom binding
15 | * 16 | *The following example shows a Java function that uses a customBinding:
23 | * 24 | *{@literal @}FunctionName("CustomBindingTriggerSample")
25 | * public void logCustomTriggerInput(
26 | * {@literal @}CustomBinding(direction = "in", name = "inputParameterName", type = "customBindingTrigger") String customTriggerInput
27 | * final ExecutionContext context
28 | * ) {
29 | * context.getLogger().info(customTriggerInput);
30 | * }
31 | *
32 | * @since 1.0.0
33 | */
34 |
35 | @Retention(RetentionPolicy.RUNTIME)
36 | public @interface CustomBinding {
37 | /**
38 | * The variable name used in function.json.
39 | * @return The variable name used in function.json.
40 | */
41 | String name();
42 |
43 | /**
44 | * The variable name used in function.json to specify the type of the binding.
45 | * @return The type of the binding.
46 | */
47 | String type();
48 |
49 | /**
50 | * The variable name used in function.json to specify the direction of the binding: in or out
51 | * @return The direction of the biding.
52 | */
53 | String direction();
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/azure/functions/annotation/FunctionName.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT License. See License.txt in the project root for
4 | * license information.
5 | */
6 |
7 | package com.microsoft.azure.functions.annotation;
8 |
9 | import java.lang.annotation.ElementType;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.RetentionPolicy;
12 | import java.lang.annotation.Target;
13 |
14 | /**
15 | * The {@code FunctionName} annotation is used to specify to the Azure Functions tooling what name is to be applied 16 | * to the associated function when the function is deployed onto Azure. This becomes the endpoint (in the case of an 17 | * {@link HttpTrigger http triggered} function, for example, but more generally it is what is shown to users in the 18 | * Azure Portal, so a succinct and understandable function name is useful.
19 | * 20 | *An example of how the {@code FunctionName} annotation is shown in the code snippet below. Note that it is applied 21 | * to the function that will be called by Azure, based on the specified trigger (in the code below it is a 22 | * {@link HttpTrigger}).
23 | * 24 | *
25 | * {@literal @}FunctionName("redirect")
26 | * public HttpResponseMessage<String> redirectFunction(
27 | * {@literal @}HttpTrigger(name = "req",
28 | * methods = {"get"}, authLevel = AuthorizationLevel.ANONYMOUS)
29 | * HttpRequestMessage<Optional<String>> request) {
30 | * ....
31 | * }
32 | *
33 | * @since 1.0.0
34 | */
35 | @Retention(RetentionPolicy.RUNTIME)
36 | @Target(ElementType.METHOD)
37 | public @interface FunctionName {
38 | /**
39 | * The name of the function.
40 | * @return The name of the function.
41 | */
42 | String value();
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/microsoft/azure/functions/annotation/EventGridTrigger.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) Microsoft Corporation. All rights reserved.
3 | * Licensed under the MIT License. See License.txt in the project root for
4 | * license information.
5 | */
6 |
7 | package com.microsoft.azure.functions.annotation;
8 |
9 | import java.lang.annotation.ElementType;
10 | import java.lang.annotation.Retention;
11 | import java.lang.annotation.RetentionPolicy;
12 | import java.lang.annotation.Target;
13 |
14 | /**
15 | * 16 | * Place this on a parameter whose value would come from EventGrid, and causing the method to run when an event is 17 | * arrived. The parameter type can be one of the following:
18 | * 19 | *The following example shows a Java function that prints out an event:
26 | * 27 | *{@literal @}FunctionName("eventGridMonitor")
28 | * public void logEvent(
29 | * {@literal @}EventGridTrigger(name = "event") String content,
30 | * final ExecutionContext context
31 | * ) {
32 | * context.getLogger().info(content);
33 | * }
34 | *
35 | * @since 1.0.0
36 | */
37 | @Retention(RetentionPolicy.RUNTIME)
38 | @Target({ElementType.PARAMETER})
39 | public @interface EventGridTrigger {
40 | /**
41 | * The variable name used in function.json.
42 | * @return The variable name used in function.json.
43 | */
44 | String name();
45 |
46 | /**
47 | * Defines how Functions runtime should treat the parameter value. Possible values are:
48 | *Place this on a parameter whose value would be written to a storage table. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *Defines how Functions runtime should treat the parameter value. Possible values are:
37 | *Place this on a parameter whose value would be sent through twilio SMS. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *Defines how Functions runtime should treat the parameter value. Possible values are:
37 | *Place this on a parameter whose value would be written to SendGrid. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *Defines how Functions runtime should treat the parameter value. Possible values are:
37 | *Place this on a parameter whose value would be published to the event hub. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *The following example shows a Java function that writes a message to an event hub:
24 | * 25 | *{@literal @}FunctionName("sendTime")
26 | *{@literal @}EventHubOutput(name = "event", eventHubName = "samples-workitems", connection = "AzureEventHubConnection")
27 | * public String sendTime(
28 | * {@literal @}TimerTrigger(name = "sendTimeTrigger", schedule = "0 */5 * * * *") String timerInfo
29 | * ) {
30 | * return LocalDateTime.now().toString();
31 | * }
32 | *
33 | * @since 1.0.0
34 | */
35 | @Retention(RetentionPolicy.RUNTIME)
36 | @Target({ElementType.PARAMETER, ElementType.METHOD})
37 | public @interface EventHubOutput {
38 | /**
39 | * The variable name used in function.json.
40 | * @return The variable name used in function.json.
41 | */
42 | String name();
43 |
44 | /**
45 | * Defines how Functions runtime should treat the parameter value. Possible values are:
46 | *16 | * Place this on a parameter whose value would be written to a service bus topic. The parameter type 17 | * should be OutputBinding<T>, where T could be one of: 18 | *
19 | * 20 | *40 | * Defines how Functions runtime should treat the parameter value. Possible values are: 41 | *
42 | *Place this on a parameter whose value would come from a storage queue, and causing the method to run when a new 16 | * item is pushed. The parameter type can be one of the following:
17 | * 18 | *The following example shows a Java function that polls the "myqueue-items" queue and writes a log each time a 25 | * queue item is processed.
26 | * 27 | *{@literal @}FunctionName("queueMonitor")
28 | * public void logQueueItem(
29 | * {@literal @}QueueTrigger(name = "msg", queueName = "myqueue-items", connection = "AzureWebJobsStorage")
30 | * String message,
31 | * final ExecutionContext context
32 | * ) {
33 | * context.getLogger().info("Queue message processed: " + message);
34 | * }
35 | *
36 | * @since 1.0.0
37 | */
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Target(ElementType.PARAMETER)
40 | public @interface QueueTrigger {
41 | /**
42 | * The variable name used in function.json.
43 | * @return The variable name used in function.json.
44 | */
45 | String name();
46 |
47 | /**
48 | * Defines how Functions runtime should treat the parameter value. Possible values are:
49 | *Place this on a parameter whose value would be written to a storage queue. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *The following example shows a Java function that creates a queue message for each HTTP request received.
24 | * 25 | *{@literal @}FunctionName("httpToQueue")
26 | *{@literal @}QueueOutput(name = "item", queueName = "myqueue-items", connection = "AzureWebJobsStorage")
27 | * public String pushToQueue(
28 | * {@literal @}HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
29 | * final String message,
30 | * {@literal @}HttpOutput(name = "response") final OutputBinding<String> result
31 | * ) {
32 | * result.setValue(message + " has been added.");
33 | * return message;
34 | * }
35 | *
36 | * @since 1.0.0
37 | */
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Target({ElementType.PARAMETER, ElementType.METHOD})
40 | public @interface QueueOutput {
41 | /**
42 | * The variable name used in function.json.
43 | * @return The variable name used in function.json.
44 | */
45 | String name();
46 |
47 | /**
48 | * Defines how Functions runtime should treat the parameter value. Possible values are:
49 | *Place this on a parameter whose value would be written to a blob. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *The following example shows blob input and output bindings in a Java function. The function makes a copy of 24 | * a text blob. The function is triggered by a queue message that contains the name of the blob to copy. The new 25 | * blob is named {originalblobname}-Copy.
26 | * 27 | *{@literal @}FunctionName("copyTextBlob")
28 | *{@literal @}StorageAccount("AzureWebJobsStorage")
29 | *{@literal @}BlobOutput(name = "target", path = "samples-workitems/{queueTrigger}-Copy")
30 | * public String blobCopy(
31 | * {@literal @}QueueTrigger(name = "filename",
32 | * queueName = "myqueue-items") String filename,
33 | * {@literal @}BlobInput(name = "source",
34 | * path = "samples-workitems/{queueTrigger}") String content
35 | * ) {
36 | * return content;
37 | * }
38 | *
39 | * @since 1.0.0
40 | */
41 | @Retention(RetentionPolicy.RUNTIME)
42 | @Target({ElementType.PARAMETER, ElementType.METHOD})
43 | public @interface BlobOutput {
44 | /**
45 | * The variable name used in function.json.
46 | * @return The variable name used in function.json.
47 | */
48 | String name();
49 |
50 | /**
51 | * Defines how Functions runtime should treat the parameter value. Possible values are:
52 | *Place this on a parameter whose value would come from a blob. The parameter type can be one of the following:
16 | * 17 | *The following example is a Java function that uses a queue trigger and an input blob binding. The queue message 24 | * contains the name of the blob, and the function logs the size of the blob.
25 | * 26 | *{@literal @}FunctionName("getBlobSize")
27 | *{@literal @}StorageAccount("AzureWebJobsStorage")
28 | * public void blobSize(
29 | * {@literal @}QueueTrigger(name = "filename",
30 | * queueName = "myqueue-items") String filename,
31 | * {@literal @}BlobInput(name = "file",
32 | * dataType = "binary",
33 | * path = "samples-workitems/{queueTrigger}") byte[] content,
34 | * final ExecutionContext context
35 | * ) {
36 | * context.getLogger().info("The size of \"" + filename + "\" is: " + content.length + " bytes");
37 | * }
38 | *
39 | *
40 | * @since 1.0.0
41 | */
42 | @Retention(RetentionPolicy.RUNTIME)
43 | @Target(ElementType.PARAMETER)
44 | public @interface BlobInput {
45 | /**
46 | * The variable name used in function.json.
47 | * @return The variable name used in function.json.
48 | */
49 | String name();
50 |
51 | /**
52 | * Defines how Functions runtime should treat the parameter value. Possible values are:
53 | *Place this on a parameter whose value would come from a blob, and causing the method to run when a blob is 16 | * uploaded. The parameter type can be one of the following:
17 | * 18 | *The following example shows a Java function that logs the filename and size when a blob is added or updated 26 | * in the "samples-workitems" container:
27 | * 28 | *{@literal @}FunctionName("blobMonitor")
29 | * public void blobMonitor(
30 | * {@literal @}BlobTrigger(name = "file",
31 | * dataType = "binary",
32 | * path = "samples-workitems/{name}",
33 | * connection = "AzureWebJobsStorage") byte[] content,
34 | * {@literal @}BindingName("name") String filename,
35 | * final ExecutionContext context
36 | * ) {
37 | * context.getLogger().info("Name: " + filename + ", Size: " + content.length + " bytes");
38 | * }
39 | *
40 | * @see com.microsoft.azure.functions.annotation.BindingName
41 | * @since 1.0.0
42 | */
43 | @Retention(RetentionPolicy.RUNTIME)
44 | @Target(ElementType.PARAMETER)
45 | public @interface BlobTrigger {
46 | /**
47 | * The variable name used in function.json.
48 | * @return The variable name used in function.json.
49 | */
50 | String name();
51 |
52 | /**
53 | * Defines how Functions runtime should treat the parameter value. Possible values are:
54 | *Place this on a parameter whose value would be written to a service bus queue. 16 | * The parameter type should be OutputBinding<T>, where T could be one of:
17 | * 18 | *The following example shows a Java function that sends a Service Bus queue message:
24 | * 25 | *{@literal @}FunctionName("httpToServiceBusQueue")
26 | *{@literal @}ServiceBusQueueOutput(name = "message", queueName = "myqueue", connection = "AzureServiceBusConnection")
27 | * public String pushToQueue(
28 | * {@literal @}HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
29 | * final String message,
30 | * {@literal @}HttpOutput(name = "response") final OutputBinding<String> result
31 | * ) {
32 | * result.setValue(message + " has been sent.");
33 | * return message;
34 | * }
35 | *
36 | * @since 1.0.0
37 | */
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Target({ElementType.PARAMETER, ElementType.METHOD})
40 | public @interface ServiceBusQueueOutput {
41 | /**
42 | * The variable name used in function.json.
43 | * @return The variable name used in function.json.
44 | */
45 | String name();
46 |
47 | /**
48 | * Defines how Functions runtime should treat the parameter value. Possible values are:
49 | *16 | * Place this on a parameter whose value would come from a Service Bus queue, and causing the method 17 | * to run when a new item is pushed. The parameter type can be one of the following: 18 | *
19 | * 20 | *27 | * The following example shows a Java function that logs a Service Bus queue message: 28 | *
29 | * 30 | *
31 | * {@literal @}FunctionName("serviceBusMonitor")
32 | * public void logServiceBusMessage(
33 | * {@literal @}ServiceBusQueueTrigger(name = "msg", queueName = "myqueue", connection = "AzureServiceBusConnection")
34 | * final String message,
35 | * final ExecutionContext context
36 | * ) {
37 | * context.getLogger().info("Message is received: " + message);
38 | * }
39 | *
40 | *
41 | * @since 1.0.0
42 | */
43 | @Retention(RetentionPolicy.RUNTIME)
44 | @Target(ElementType.PARAMETER)
45 | public @interface ServiceBusQueueTrigger {
46 | /**
47 | * The variable name used in function.json.
48 | *
49 | * @return The variable name used in function.json.
50 | */
51 | String name();
52 |
53 | /**
54 | * 55 | * Defines how Functions runtime should treat the parameter value. Possible values are: 56 | *
57 | *Place this on a parameter whose value would come from event hub, and causing the method to run when a new event is 16 | * arrived. The parameter type can be one of the following:
17 | * 18 | *The following example shows a Java function that logs the message body of the event hub trigger:
25 | * 26 | *{@literal @}FunctionName("eventHubMonitor")
27 | * public void logEventHubMessage(
28 | * {@literal @}EventHubTrigger(name = "event",
29 | * eventHubName = "samples-workitems",
30 | * connection = "AzureEventHubConnection") String message,
31 | * final ExecutionContext context
32 | * ) {
33 | * context.getLogger().info("Event hub message received: " + message);
34 | * }
35 | *
36 | * @since 1.0.0
37 | */
38 | @Retention(RetentionPolicy.RUNTIME)
39 | @Target(ElementType.PARAMETER)
40 | public @interface EventHubTrigger {
41 | /**
42 | * The variable name used in function.json.
43 | * @return The variable name used in function.json.
44 | */
45 | String name();
46 |
47 | /**
48 | * Defines how Functions runtime should treat the parameter value. Possible values are:
49 | *16 | * Place this on a parameter whose value would come from Service Bus topic, and causing the method 17 | * to run when a new item is published. The parameter type can be one of the following: 18 | *
19 | * 20 | *27 | * The following example shows a service bus topic trigger which logs the message: 28 | *
29 | * 30 | *
31 | * {@literal @}FunctionName("sbprocessor")
32 | * public void serviceBusProcess(
33 | * {@literal @}ServiceBusTopicTrigger(name = "msg",
34 | * topicName = "mytopicname",
35 | * subscriptionName = "mysubname",
36 | * connection = "myconnvarname") String message,
37 | * final ExecutionContext context
38 | * ) {
39 | * context.getLogger().info(message);
40 | * }
41 | *
42 | *
43 | * @since 1.0.0
44 | */
45 | @Retention(RetentionPolicy.RUNTIME)
46 | @Target(ElementType.PARAMETER)
47 | public @interface ServiceBusTopicTrigger {
48 | /**
49 | * The variable name used in function.json.
50 | *
51 | * @return The variable name used in function.json.
52 | */
53 | String name();
54 |
55 | /**
56 | * 57 | * Defines how Functions runtime should treat the parameter value. Possible values are: 58 | *
59 | *Place this on a parameter whose value would come from storage table. 16 | * The parameter type can be one of the following:
17 | * 18 | *The following example shows an HTTP trigger which returned the total count of the items in a table storage:
25 | * 26 | *{@literal @}FunctionName("getallcount")
27 | * public int run(
28 | * {@literal @}HttpTrigger(name = "req",
29 | * methods = {"get"},
30 | * authLevel = AuthorizationLevel.ANONYMOUS) Object dummyShouldNotBeUsed,
31 | * {@literal @}TableInput(name = "items",
32 | * tableName = "mytablename",
33 | * partitionKey = "myparkey",
34 | * connection = "myconnvarname") MyItem[] items
35 | * ) {
36 | * return items.length;
37 | * }
38 | *
39 | * @see com.microsoft.azure.functions.annotation.HttpTrigger
40 | * @since 1.0.0
41 | */
42 | @Retention(RetentionPolicy.RUNTIME)
43 | @Target(ElementType.PARAMETER)
44 | public @interface TableInput {
45 | /**
46 | * The variable name used in function.json.
47 | * @return The variable name used in function.json.
48 | */
49 | String name();
50 |
51 | /**
52 | * Defines how Functions runtime should treat the parameter value. Possible values are:
53 | *An example of using the timer trigger is shown below, where the {@code keepAlive} function is set to trigger and 20 | * execute every five minutes:
21 | * 22 | *{@literal @}FunctionName("keepAlive")
23 | * public void keepAlive(
24 | * {@literal @}TimerTrigger(name = "keepAliveTrigger", schedule = "0 */5 * * * *") String timerInfo,
25 | * ExecutionContext context
26 | * ) {
27 | * // timeInfo is a JSON string, you can deserialize it to an object using your favorite JSON library
28 | * context.getLogger().info("Timer is triggered: " + timerInfo);
29 | * }
30 | *
31 | * @since 1.0.0
32 | */
33 | @Retention(RetentionPolicy.RUNTIME)
34 | @Target(ElementType.PARAMETER)
35 | public @interface TimerTrigger {
36 | /**
37 | * The name of the variable that represents the timer object in function code.
38 | *
39 | * @return The name of the variable that represents the timer object in function code.
40 | */
41 | String name();
42 |
43 | /**
44 | * Defines how Functions runtime should treat the parameter value. Possible values are:
45 | *| Goal | 62 | *CRON Expression | 63 | *
|---|---|
| To trigger once every five minutes: | 66 | *0 */5 * * * * | 67 | *
| To trigger once at the top of every hour: | 70 | *0 0 * * * * | 71 | *
| To trigger once every two hours: | 74 | *0 0 */2 * * * | 75 | *
| To trigger once every hour from 9 AM to 5 PM: | 78 | *0 0 9-17 * * * | 79 | *
| To trigger at 9:30 AM every day: | 82 | *0 30 9 * * * | 83 | *
| To trigger at 9:30 AM every weekday: | 86 | *0 30 9 * * 1-5 | 87 | *
16 | * Place this on a parameter whose value would come from CosmosDB. The parameter 17 | * type can be one of the following: 18 | *
19 | * 20 | *28 | * The following example shows a Java function that retrieves a single document. 29 | * The function is triggered by an HTTP request that uses a query string to 30 | * specify the ID to look up. That ID is used to retrieve a ToDoItem document 31 | * from the specified database and collection. A sample URL would be like: 32 | * http://localhost:7071/api/getItem?id=myid. 33 | *
34 | * 35 | *
36 | * {@literal @}FunctionName("getItem")
37 | * public String cosmosDbQueryById(
38 | * {@literal @}HttpTrigger(name = "req",
39 | * methods = {HttpMethod.GET},
40 | * authLevel = AuthorizationLevel.ANONYMOUS) Optional<String> dummy,
41 | * {@literal @}CosmosDBInput(name = "database",
42 | * databaseName = "ToDoList",
43 | * collectionName = "Items",
44 | * id = "{Query.id}",
45 | * connectionStringSetting = "AzureCosmosDBConnection") Optional<String> item
46 | * ) {
47 | * return item.orElse("Not found");
48 | * }
49 | *
50 | *
51 | * @since 1.0.0
52 | */
53 | @Retention(RetentionPolicy.RUNTIME)
54 | @Target(ElementType.PARAMETER)
55 | public @interface CosmosDBInput {
56 | /**
57 | * The variable name used in function.json.
58 | *
59 | * @return The variable name used in function.json.
60 | */
61 | String name();
62 |
63 | /**
64 | * 65 | * Defines how Functions runtime should treat the parameter value. Possible 66 | * values are: 67 | *
68 | *16 | * Place this on a parameter whose value would be written to CosmosDB. The parameter type should be 17 | * OutputBinding<T>, where T could be one of: 18 | *
19 | * 20 | *26 | * The following example shows a Java function that adds a document to a database, using data 27 | * provided in the body of an HTTP Post request. 28 | *
29 | * 30 | *
31 | * {@literal @}FunctionName("addItem")
32 | *
33 | * public String cosmosDbAddItem(
34 | * {@literal @}HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
35 | * final String message,
36 | * {@literal @}CosmosDBOutput(name = "database", databaseName = "ToDoList", collectionName = "Items",
37 | * connectionStringSetting = "AzureCosmosDBConnection")
38 | * ) {
39 | * return "{ \"id\": \"" + System.currentTimeMillis() + "\", \"description\": \"" + message + "\" }";
40 | * }
41 | *
42 | *
43 | * @since 1.0.0
44 | */
45 | @Retention(RetentionPolicy.RUNTIME)
46 | @Target({ ElementType.PARAMETER, ElementType.METHOD })
47 | public @interface CosmosDBOutput {
48 | /**
49 | * The variable name used in function.json.
50 | *
51 | * @return The variable name used in function.json.
52 | */
53 | String name();
54 |
55 | /**
56 | * 57 | * Defines how Functions runtime should treat the parameter value. Possible values are: 58 | *
59 | *16 | * Place this on a parameter whose value would come from CosmosDB, and causing the method to run 17 | * when CosmosDB data is changed. The parameter type can be one of the following: 18 | *
19 | * 20 | *27 | * The following example shows a Java function that is invoked when there are inserts or updates in 28 | * the specified database and collection. 29 | *
30 | * 31 | *
32 | * {@literal @}FunctionName("cosmosDBMonitor")
33 | * public void cosmosDbLog(
34 | * {@literal @}CosmosDBTrigger(name = "database",
35 | * databaseName = "ToDoList",
36 | * collectionName = "Items",
37 | * leaseCollectionName = "leases",
38 | * createLeaseCollectionIfNotExists = true,
39 | * connectionStringSetting = "AzureCosmosDBConnection")
40 | * List<Map<String, String>> items,
41 | * final ExecutionContext context
42 | * ) {
43 | * context.getLogger().info(items.size() + " item(s) is/are inserted.");
44 | * if (!items.isEmpty()) {
45 | * context.getLogger().info("The ID of the first item is: " + items.get(0).get("id"));
46 | * }
47 | * }
48 | *
49 | *
50 | * @since 1.0.0
51 | */
52 | @Retention(RetentionPolicy.RUNTIME)
53 | @Target({ ElementType.PARAMETER })
54 | public @interface CosmosDBTrigger {
55 | /**
56 | * The variable name used in function.json.
57 | *
58 | * @return The variable name used in function.json.
59 | */
60 | String name();
61 |
62 | /**
63 | * 64 | * Defines how Functions runtime should treat the parameter value. Possible values are: 65 | *
66 | *18 | * The HttpTrigger annotation is applied to Azure functions that will be triggered by a call to the 19 | * HTTP endpoint that the function is located at. The HttpTrigger annotation should be applied to a 20 | * method parameter of one of the following types: 21 | *
22 | * 23 | *31 | * For example: 32 | *
33 | * 34 | *
35 | * {@literal @}FunctionName("hello")
36 | * public HttpResponseMessage<String> helloFunction(
37 | * {@literal @}HttpTrigger(name = "req",
38 | * methods = {HttpMethod.GET},
39 | * authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request
40 | * ) {
41 | * ....
42 | * }
43 | *
44 | *
45 | *
46 | * In this code snippet you will observe that we have a function annotated with
47 | * {@code @FunctionName("hello")}, which indicates that this function will be available at the
48 | * endpoint /api/hello. The name of the method itself, in this case {@code helloFunction} is
49 | * irrelevant for all intents and purposes related to Azure Functions. Note however that the method
50 | * return type is {@link com.microsoft.azure.functions.HttpResponseMessage}, and that the first
51 | * argument into the function is an {@link com.microsoft.azure.functions.HttpRequestMessage} with
52 | * generic type {@code Optional
57 | * Most important of all however is the {@code @HttpTrigger} annotation that has been applied to 58 | * this argument. In this annotation you'll note that it has been given a name, as well as told what 59 | * type of requests it supports (in this case, only HTTP GET requests), and that the 60 | * {@link AuthorizationLevel} is anonymous, allowing access to anyone who can call the endpoint. 61 | *
62 | * 63 | *64 | * The {@code HttpTrigger} can be further customised by providing a custom {@link #route()}, which 65 | * allows for custom endpoints to be specified, and for these endpoints to be parameterized with 66 | * arguments being bound to arguments provided to the function at runtime. 67 | *
68 | * 69 | *70 | * The following example shows a Java function that looks for a name parameter either in the query 71 | * string (HTTP GET) or the body (HTTP POST) of the HTTP request. Notice that the return value is 72 | * used for the output binding, but a return value attribute isn't required. 73 | *
74 | * 75 | *
76 | * {@literal @}FunctionName("readHttpName")
77 | * public String readName(
78 | * {@literal @}HttpTrigger(name = "req",
79 | * methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
80 | * final HttpRequestMessage<Optional<String>> request) {
81 | * String name = request.getBody().orElseGet(() -> request.getQueryParameters().get("name"));
82 | * return name == null ?
83 | * "Please pass a name on the query string or in the request body" :
84 | * "Hello " + name;
85 | * }
86 | *
87 | *
88 | * @see com.microsoft.azure.functions.HttpRequestMessage
89 | * @see com.microsoft.azure.functions.HttpResponseMessage
90 | * @since 1.0.0
91 | */
92 | @Retention(RetentionPolicy.RUNTIME)
93 | @Target(ElementType.PARAMETER)
94 | public @interface HttpTrigger {
95 | /**
96 | * The variable name used in function code for the request or request body.
97 | *
98 | * @return The variable name used in function code for the request or request body.
99 | */
100 | String name();
101 |
102 | /**
103 | * 104 | * Defines how Functions runtime should treat the parameter value. Possible values are: 105 | *
106 | *120 | * Defines the route template, controlling which request URLs your function will respond to. The 121 | * default value if no route is provided is the function name specified in the 122 | * {@link FunctionName} annotation, applied to each Azure Function. 123 | *
124 | * 125 | *126 | * By default when you create a function for an HTTP trigger, or WebHook, the function is 127 | * addressable with a route of the form 128 | * {@code http://<yourapp>.azurewebsites.net/api/<funcname>}. You can customize this 129 | * route using this route property. For example, a route of 130 | * {@code "products/{category:alpha}/{id:int}"} would mean that the function is now addressable 131 | * with the following route instead of the original route: 132 | * {@code http://<yourapp>.azurewebsites.net/api/products/electronics/357}, which allows the 133 | * function code to support two parameters in the address: category and id. By specifying the 134 | * route in this way, developers can then add the additional route arguments as arguments into the 135 | * function by using the {@link BindingName} annotation. For example: 136 | *
137 | * 138 | *
139 | * {@literal @}FunctionName("routeTest")
140 | * public HttpResponseMessage<String> routeTest(
141 | * {@literal @}HttpTrigger(name = "req",
142 | * methods = {HttpMethod.GET},
143 | * authLevel = AuthorizationLevel.ANONYMOUS,
144 | * route = "products/{category:alpha}/{id:int}")
145 | * HttpRequestMessage<Optional<String>> request,
146 | * {@literal @}BindingName("category") String category,
147 | * {@literal @}BindingName("id") int id,
148 | * final ExecutionContext context
149 | * ) {
150 | * ....
151 | * context.getLogger().info("We have " + category + " with id " + id);
152 | * ....
153 | * }
154 | *
155 | *
156 | * 157 | * For more details on the route syntax, refer to the 159 | * online documentation. 160 | *
161 | * 162 | * @return The route template to use for the annotated function. 163 | */ 164 | String route() default ""; 165 | 166 | /** 167 | * An array of the HTTP methods to which the function responds. If not specified, the function 168 | * responds to all HTTP methods. 169 | * 170 | * @return An array containing all valid HTTP methods. 171 | */ 172 | HttpMethod[] methods() default {}; 173 | 174 | /** 175 | *176 | * Determines what keys, if any, need to be present on the request in order to invoke the 177 | * function. The authorization level can be one of the following values: 178 | *
179 | * 180 | *188 | * For more information, see the documentation 190 | * about authorization keys. 191 | *
192 | * 193 | * @return An {@link AuthorizationLevel} value representing the level required to access the 194 | * function. 195 | */ 196 | AuthorizationLevel authLevel() default AuthorizationLevel.FUNCTION; 197 | } 198 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library for Azure Java Functions 2 | This repo contains library for building Azure Java Functions. Visit the [complete documentation of Azure Functions - Java Developer Guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java) for more details. 3 | 4 | ## azure-functions-maven plugin 5 | [How to use azure-functions-maven plugin to create, update, deploy and test azure java functions](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme?view=azure-java-stable) 6 | 7 | ## Prerequisites 8 | 9 | * Java 8 10 | 11 | ## Parent POM 12 | 13 | Please see for details on Parent POM https://github.com/Microsoft/maven-java-parent 14 | 15 | ## Summary 16 | 17 | Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it. Functions can make development even more productive.Pay only for the time your code runs and trust Azure to scale as needed. Azure Functions lets you develop [serverless](https://azure.microsoft.com/en-us/solutions/serverless/) applications on Microsoft Azure. 18 | 19 | Azure Functions supports triggers, which are ways to start execution of your code, and bindings, which are ways to simplify coding for input and output data. A function should be a stateless method to process input and produce output. Although you are allowed to write instance methods, your function must not depend on any instance fields of the class. You need to make sure all the function methods are `public` accessible and method with annotation @FunctionName is unique as that defines the entry for the the function. 20 | 21 | A deployable unit is an uber JAR containing one or more functions (see below), and a JSON file with the list of functions and triggers definitions, deployed to Azure Functions. The JAR can be created in many ways, although we recommend [Azure Functions Maven Plugin](https://docs.microsoft.com/en-us/java/api/overview/azure/maven/azure-functions-maven-plugin/readme), as it provides templates to get you started with key scenarios. 22 | 23 | All the input and output bindings can be defined in `function.json` (not recommended), or in the Java method by using annotations (recommended). All the types and annotations used in this document are included in the `azure-functions-java-library` package. 24 | 25 | ### Sample 26 | 27 | Here is an example of a HttpTrigger Azure function in Java: 28 | 29 | 30 | ```java 31 | package com.example; 32 | 33 | import com.microsoft.azure.functions.annotation.*; 34 | 35 | public class Function { 36 | @FunctionName("echo") 37 | public static String echo(@HttpTrigger(name = "req", methods = { "post" }, authLevel = AuthorizationLevel.ANONYMOUS) String in) { 38 | return "Hello, " + in + "."; 39 | } 40 | } 41 | ``` 42 | 43 | ### Adding 3rd Party Libraries 44 | 45 | Azure Functions supports the use of 3rd party libraries. If using the Maven plugin for Azure Functions, all of your dependencies specified in your `pom.xml` file will be automatically bundled during the `mvn package` step. 46 | 47 | ## Data Types 48 | 49 | You are free to use all the data types in Java for the input and output data, including native types; customized POJO types and specialized Azure types defined in this API. Azure Functions runtime will try its best to convert the actual input value to the type you need (for example, a `String` input will be treated as a JSON string and be parsed to a POJO type defined in your code). 50 | 51 | ### JSON Support 52 | The POJO types (Java classes) you may define have to be publicly accessible (`public` modifier). POJO properties/fields may be `private`. For example a JSON string `{ "x": 3 }` is able to be converted to the following POJO type: 53 | 54 | ```java 55 | public class PojoData { 56 | private int x; 57 | } 58 | ``` 59 | 60 | ### Other supported types 61 | Binary data is represented as `byte[]` or `Byte[]` in your Azure functions code. And make sure you specify `dataType = "binary"` in the corresponding triggers/bindings. 62 | 63 | Empty input values could be `null` as your functions argument, but a recommended way to deal with potential empty values is to use `Optional