您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

com.microsoft.azure.functions.annotation

Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See License.txt in the project root for license information. Annotations and support classes for use as part of the Java API for Azure Functions.

Classes

BindingTest

Unit tests that enforce annotation contracts and conventions for Functions

Interfaces

BindingName

Place this on a parameter whose value would come from Azure Functions runtime. Use this annotation when you want to get the value of trigger metadata, or when you defined your own bindings in function.json manually.

BlobInput

BlobInput(name = "file", dataType = "binary", path = "samples-workitems/{queueTrigger}") byte[] content, final ExecutionContext context ) { context.getLogger().info("The size of \"" + filename + "" is: " + content.length + " bytes"); }

BlobOutput

BlobInput(name = "source", path = "samples-workitems/{queueTrigger}") String content ) { return content; }

BlobTrigger

BindingName("name") String filename, final ExecutionContext context ) { context.getLogger().info("Name: " + filename + ", Size: " + content.length + " bytes"); }

CosmosDBInput

CosmosDBInput(name = "database", databaseName = "ToDoList", collectionName = "Items", id = "{Query.id}", connectionStringSetting = "AzureCosmosDBConnection") Optional<String> item ) { return item.orElse("Not found"); }

CosmosDBOutput

CosmosDBOutput(name = "database", databaseName = "ToDoList", collectionName = "Items", connectionStringSetting = "AzureCosmosDBConnection") ) { return "{ \"id": "" + System.currentTimeMillis() + "", "description": "" + message + "" }"; }

CosmosDBTrigger

CosmosDBTrigger(name = "database", databaseName = "ToDoList", collectionName = "Items", leaseCollectionName = "leases", createLeaseCollectionIfNotExists = true, connectionStringSetting = "AzureCosmosDBConnection") List<Map<String, String>> items, final ExecutionContext context ) { context.getLogger().info(items.size() + " item(s) is/are inserted."); if (!items.isEmpty()) { context.getLogger().info("The ID of the first item is: " + items.get(0).get("id")); } }

CustomBinding

CustomBinding(direction = "in", name = "inputParameterName", type = "customBindingTrigger") String customTriggerInput final ExecutionContext context ) { context.getLogger().info(customTriggerInput); }

EventGridTrigger

EventGridTrigger(name = "event") String content, final ExecutionContext context ) { context.getLogger().info(content); }

EventHubOutput

TimerTrigger(name = "sendTimeTrigger", schedule = "0 *&#47;5 * * * *") String timerInfo ) { return LocalDateTime.now().toString(); }

EventHubTrigger

EventHubTrigger(name = "event", eventHubName = "samples-workitems", connection = "AzureEventHubConnection") String message, final ExecutionContext context ) { context.getLogger().info("Event hub message received: " + message); }

FunctionName

HttpTrigger(name = "req", methods = {"get"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request) { .... }

HttpOutput

Place this on a parameter whose value would be send back to the user as an HTTP response. The parameter type should be OutputBinding<T>, where T could be one of:

HttpTrigger

HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) final HttpRequestMessage<Optional<String>> request) { String name = request.getBody().orElseGet(() -> request.getQueryParameters().get("name")); return name == null ? "Please pass a name on the query string or in the request body" : "Hello " + name; }

QueueOutput

HttpOutput(name = "response") final OutputBinding<String> result ) { result.setValue(message + " has been added."); return message; }

QueueTrigger

QueueTrigger(name = "msg", queueName = "myqueue-items", connection = "AzureWebJobsStorage") String message, final ExecutionContext context ) { context.getLogger().info("Queue message processed: " + message); }

SendGridOutput

Place this on a parameter whose value would be written to SendGrid. The parameter type should be OutputBinding<T>, where T could be one of:

  • Any native Java types such as int, String, byte[]

  • Any POJO type

ServiceBusQueueOutput

HttpOutput(name = "response") final OutputBinding<String> result ) { result.setValue(message + " has been sent."); return message; }

ServiceBusQueueTrigger

ServiceBusQueueTrigger(name = "msg", queueName = "myqueue", connection = "AzureServiceBusConnection") final String message, final ExecutionContext context ) { context.getLogger().info("Message is received: " + message); }

ServiceBusTopicOutput

Place this on a parameter whose value would be written to a service bus topic. The parameter type should be OutputBinding<T>, where T could be one of:

  • Any native Java types such as int, String, byte[]

  • Any POJO type

ServiceBusTopicTrigger

ServiceBusTopicTrigger(name = "msg", topicName = "mytopicname", subscriptionName = "mysubname", connection = "myconnvarname") String message, final ExecutionContext context ) { context.getLogger().info(message); }

StorageAccount

Apply this annotation to a method if you have multiple Azure Storage triggers/input/output in that method which share the same app setting name of Azure Storage connection string.

TableInput

TableInput(name = "items", tableName = "mytablename", partitionKey = "myparkey", connection = "myconnvarname") MyItem[] items ) { return items.length; }

TableOutput

Place this on a parameter whose value would be written to a storage table. The parameter type should be OutputBinding<T>, where T could be one of:

  • Any native Java types such as int, String, byte[]

  • Any POJO type

TimerTrigger

TimerTrigger(name = "keepAliveTrigger", schedule = "0 *&#47;5 * * * *") String timerInfo, ExecutionContext context ) { // timeInfo is a JSON string, you can deserialize it to an object using your favorite JSON library context.getLogger().info("Timer is triggered: " + timerInfo); }

TwilioSmsOutput

Place this on a parameter whose value would be sent through twilio SMS. The parameter type should be OutputBinding<T>, where T could be one of:

  • Any native Java types such as int, String, byte[]

  • Any POJO type

Enums

AccessRights

Azure Service Bus permission.

AuthorizationLevel

Azure HTTP authorization level, Determines what keys, if any, need to be present on the request in order to invoke the function.

Cardinality

Cardinality of the EventHubTrigger input. Choose 'ONE' if the input is a single message or 'Many' if the input is an array of messages. 'Many' is the default if unspecified