Azure Functions Java Library 1.4.2-SNAPSHOT
amamounelsayed
released this
21 Jan 01:06
·
64 commits
to dev
since this release
Add support for Retry policies
For more details
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-error-pages?tabs=java#fixed-delay-retry
- https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-error-pages?tabs=java#exponential-backoff-retry
FixedDelayRetry sample
@FunctionName("HttpExampleRetry")
@FixedDelayRetry(maxRetryCount = 3, delayInterval = "00:00:05")
public HttpResponseMessage runRetry(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) throws Exception {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body(name).build();
}
}
ExponentialBackoffRetry sample
@FunctionName("HttpExampleExponentialBackoffRetry")
@ExponentialBackoffRetry(maxRetryCount = 3, minimumInterval = "00:00:01", maximumInterval = "00:00:03")
public HttpResponseMessage runRetryExponentialBackoffRetry(
@HttpTrigger(
name = "req",
methods = {HttpMethod.GET, HttpMethod.POST},
authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context) throws Exception {
context.getLogger().info("Java HTTP trigger processed a request.");
// Parse query parameter
final String query = request.getQueryParameters().get("name");
final String name = request.getBody().orElse(query);
if (name == null) {
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
} else {
return request.createResponseBuilder(HttpStatus.OK).body(name).build();
}
}
Add support service batch message for ServiceBusQueueTrigger and ServiceBusTopicTrigger
@FunctionName("ServiceBusQueueBatchTrigger")
public void serviceBusQueueBatchTrigger(
@ServiceBusQueueTrigger(name = "message", queueName = "SBQueueNameBatch", connection = "AzureWebJobsServiceBus", cardinality = Cardinality.MANY, dataType = "String") String[] messages,
@QueueOutput(name = "output", queueName = "test-servicebusqueuebatch-java", connection = "AzureWebJobsStorage") OutputBinding<String> output,
final ExecutionContext context
) {
context.getLogger().info("Java Service Bus Queue trigger function processed a message: " + messages[0]);
output.setValue(messages[0]);
}
@FunctionName("ServiceBusTopicBatchTrigger")
public void serviceBusTopicBatchTrigger(
@ServiceBusTopicTrigger(name = "message", topicName = "SBTopicNameBatch", subscriptionName="SBTopicNameBatchSubName",connection = "AzureWebJobsServiceBus", cardinality = Cardinality.MANY, dataType = "String") List<String> messages,
@QueueOutput(name = "output", queueName = "test-servicebustopicbatch-java", connection = "AzureWebJobsStorage") OutputBinding<String> output,
final ExecutionContext context
) {
context.getLogger().info("Java Service Bus Topic trigger function processed a message: " + messages.get(0));
output.setValue(messages.get(0));
}