Skip to content

Releases: Azure/azure-functions-java-library

Azure Functions Java Library 1.4.2

28 Jan 04:33
2b4b6ab

Choose a tag to compare

Azure Functions Java Library 1.4.2-SNAPSHOT

21 Jan 01:06
0098603

Choose a tag to compare

Add support for Retry policies

For more details

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));
    }

Azure Functions Java Library 1.4.0

03 Sep 16:43
3b11c0b

Choose a tag to compare

Azure Functions Java Library 1.4.0-SNAPSHOT

16 Jul 04:19

Choose a tag to compare

Add Support for Kafka #118 #121

For more details and samples, you can refer to Azure Functions extensions for Apache Kafka.

KafkaTrigger sample

package com.contoso.kafka;

import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

/**
 * Azure Functions with HTTP Trigger.
 */
public class TriggerFunction {
    /**
     * This function consume KafkaEvents on the localhost. Change the topic, brokerList, and consumerGroup to fit your enviornment.
     * The function is trigged one for each KafkaEvent
     * @param kafkaEventData
     * @param context
     */
    @FunctionName("KafkaTrigger-Java")
    public void runOne(
            @KafkaTrigger(topic = "users", brokerList="broker:29092",consumerGroup="functions") String kafkaEventData,
            final ExecutionContext context) {
        context.getLogger().info(kafkaEventData);
    }
}

Kafka Output binding sample

package com.contoso.kafka;

import java.util.*;
import com.microsoft.azure.functions.annotation.*;
import com.microsoft.azure.functions.*;

import java.util.Optional;

public class FunctionOutput {
    /**
     * This function listens at endpoint "api/KafkaInput-Java" and send message to the conluent-topic. Two ways to invoke it using "curl" command in bash:
     * 1. curl -d "HTTP BODY" {your host}/api/KafkaInput-Java
     * 2. curl "{your host}/api/KafkaInput-Java?message=hello"
     * This sample is for a local cluster. Modify topic and brokerList on the @KafkaOutput annotataion
     * For the Confluence Cloud example, please refer the KafkaTrigger-Java-Many on the `TriggerFunction.java`.
     */
    @FunctionName("KafkaInput-Java")
    public HttpResponseMessage input(
            @HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
            @KafkaOutput(topic = "users", brokerList="broker:29092")  OutputBinding<String> output,
            final ExecutionContext context) {
        context.getLogger().info("Java HTTP trigger processed a request.");

        // Parse query parameter
        String query = request.getQueryParameters().get("message");
        String message = request.getBody().orElse(query);
        context.getLogger().info("Message:" + message);
        output.setValue(message);
        return request.createResponseBuilder(HttpStatus.OK).body("Message Sent, " + message).build();
    }
}

Adding support for Event Grid output binding on Java #112

String sample

public class Function {
    @FunctionName("EventGridTriggerTest")
    public void run(@EventGridTrigger(name = "event") String content,
            @EventGridOutput(name = "outputEvent", topicEndpointUri = "MyEventGridTopicUriSetting", topicKeySetting = "MyEventGridTopicKeySetting") OutputBinding<String> outputEvent,
            final ExecutionContext context) {
        context.getLogger().info("Java EventGrid trigger processed a request." + content);
        final String eventGridOutputDocument = "{\"id\": \"1807\", \"eventType\": \"recordInserted\", \"subject\": \"myapp/cars/java\", \"eventTime\":\"2017-08-10T21:03:07+00:00\", \"data\": {\"make\": \"Ducati\",\"model\": \"Monster\"}, \"dataVersion\": \"1.0\"}";
        outputEvent.setValue(eventGridOutputDocument);
    }
}

POJO sample

public class Function {
    @FunctionName("EventGridTriggerTest")
    public void run(@EventGridTrigger(name = "event") String content,
            @EventGridOutput(name = "outputEvent", topicEndpointUri = "MyEventGridTopicUriSetting", topicKeySetting = "MyEventGridTopicKeySetting") OutputBinding<EventGridEvent> outputEvent,
            final ExecutionContext context) {
        context.getLogger().info("Java EventGrid trigger processed a request." + content);

        final EventGridEvent eventGridOutputDocument = new EventGridEvent();
        eventGridOutputDocument.setId("1807");
        eventGridOutputDocument.setEventType("recordInserted");
        eventGridOutputDocument.setEventTime("2017-08-10T21:03:07+00:00");
        eventGridOutputDocument.setDataVersion("1.0");
        eventGridOutputDocument.setSubject("myapp/cars/java");
        eventGridOutputDocument.setData("{\"make\": \"Ducati\",\"model\":\"monster\"");

        outputEvent.setValue(eventGridOutputDocument);
    }
}

class EventGridEvent {
    private String id;
    private String eventType;
    private String subject;
    private String eventTime;
    private String dataVersion;
    private String data;

    public String getId() {
        return id;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getDataVersion() {
        return dataVersion;
    }

    public void setDataVersion(String dataVersion) {
        this.dataVersion = dataVersion;
    }

    public String getEventTime() {
        return eventTime;
    }

    public void setEventTime(String eventTime) {
        this.eventTime = eventTime;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getEventType() {
        return eventType;
    }

    public void setEventType(String eventType) {
        this.eventType = eventType;
    }

    public void setId(String id) {
        this.id = id;
    }  
}

Azure Functions Java Library 1.3.1

04 Dec 01:33

Choose a tag to compare

Azure Functions Java Library 1.3.1-SNAPSHOT

20 Sep 20:13

Choose a tag to compare

Release Notes

  • Added support for TraceContext on ExecutionContext.
  • Added support to specify isSessionsEnabled on ServiceBusQueueTrigger and ServiceBusTopicTrigger annotations.

Azure Functions Java Library 1.3.0

26 Feb 17:42
bbccf57

Choose a tag to compare

Azure Functions Java Library 1.3.0-SNAPSHOT

29 Jan 23:52
17b32d9

Choose a tag to compare

Release Notes

  • Added support for custombinding. Sample code for using custom binding
package com.microsoft.azure.functions.worker.broker.tests;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

import com.microsoft.azure.functions.annotation.CustomBinding;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@CustomBinding(direction = "in", name = "message", type = "customBinding")
public @interface TestCustomBinding {
   String index();
   String path();
}

public void CustomBinding_Valid(@HttpTrigger(name = "req", methods = { HttpMethod.GET,
      HttpMethod.POST }, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<String> request,
      @TestCustomBinding(index = "testIndex", path = "testPath") String customInput) {
  }

Azure Functions Java Library 1.2.2

22 Jan 16:52
f6d5288

Choose a tag to compare

Release Notes

Azure Functions Java Library 1.2.0

09 Nov 11:30
374d791

Choose a tag to compare

This release

  • Added Parent POM
  • Deleted unsupported MobileTable annotations
  • Updated sample code in readme