Annotation Type KafkaTrigger


  • @Target(PARAMETER)
    @Retention(RUNTIME)
    public @interface KafkaTrigger

    Place this on a parameter whose value would come from Kafka, and causing the method to run when Kafka event is consumed. The parameter type can be one of the following:

    • Any native Java types such as int, String, byte[]
    • Nullable values using Optional<T>
    • Any POJO type, currently supported only for Cardinality.One

    The following example shows a Java function that is invoked when messages are consumed with the specified topic, brokerList, and consumerGroup on a Kafka cluster.

     @FunctionName("KafkaTrigger-Java")
     public void run(
        @KafkaTrigger(name = "kafkaTrigger",
                          topic = "users", 
                          brokerList="broker:29092",
                          consumerGroup="functions")
                          List<Map<String, String>> kafkaEventData,
         final ExecutionContext context
     ) {
         context.getLogger().info(kafkaEventData);
     }
     
    Since:
    1.4.0
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.String brokerList
      Defines the BrokerList.
      java.lang.String consumerGroup
      Defines the consumer group.
      java.lang.String name
      The variable name used in function code for the request or request body.
      java.lang.String topic
      Defines the Topic.
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      com.microsoft.azure.functions.BrokerAuthenticationMode authenticationMode
      SASL mechanism to use for authentication.
      java.lang.String avroSchema
      Avro schema for generic record deserialization default ""
      Cardinality cardinality
      Cardinality of the trigger input.
      java.lang.String dataType
      Defines how Functions runtime should treat the parameter value.
      java.lang.String eventHubConnectionString
      Defines the EventHub connection string when using KafkaOutput protocol header feature of Azure EventHubs.
      int lagThreshold  
      java.lang.String password
      SASL password with the PLAIN and SASL-SCRAM-..
      com.microsoft.azure.functions.BrokerProtocol protocol
      Defines the security protocol used to communicate with brokers default is NOTSET
      java.lang.String schemaRegistryPassword
      Password for the Avro Schema Registry default ""
      java.lang.String schemaRegistryUrl
      URL for the Avro Schema Registry default ""
      java.lang.String schemaRegistryUsername
      Username for the Avro Schema Registry default ""
      java.lang.String sslCaLocation
      Path to CA certificate file for verifying the broker's certificate.
      java.lang.String sslCertificateLocation
      Path to client's certificate.
      java.lang.String sslKeyLocation
      Path to client's private key (PEM) used for authentication.
      java.lang.String sslKeyPassword
      Password for client's certificate.
      java.lang.String username
      SASL username with the PLAIN and SASL-SCRAM-..
    • Element Detail

      • name

        java.lang.String name
        The variable name used in function code for the request or request body.
        Returns:
        The variable name used in function code for the request or request body.
      • topic

        java.lang.String topic
        Defines the Topic.
        Returns:
        The topic.
      • brokerList

        java.lang.String brokerList
        Defines the BrokerList.
        Returns:
        The brokerList.
      • consumerGroup

        java.lang.String consumerGroup
        Defines the consumer group.
        Returns:
        The consumer group.
      • eventHubConnectionString

        java.lang.String eventHubConnectionString
        Defines the EventHub connection string when using KafkaOutput protocol header feature of Azure EventHubs.
        Returns:
        The EventHub connection string.
        Default:
        ""
      • cardinality

        Cardinality cardinality
        Cardinality of the trigger input. Choose 'One' if the input is a single message or 'Many' if the input is an array of messages. If you choose 'Many', please set a dataType. Default: 'One'
        Returns:
        The cardinality.
        Default:
        com.microsoft.azure.functions.annotation.Cardinality.ONE
      • dataType

        java.lang.String dataType

        Defines how Functions runtime should treat the parameter value. Possible values are:

        • "": get the value as a string, and try to deserialize to actual parameter type like POJO
        • string: always get the value as a string
        • binary: get the value as a binary data, and try to deserialize to actual parameter type byte[]
        Returns:
        The dataType which will be used by the Functions runtime.
        Default:
        ""
      • authenticationMode

        com.microsoft.azure.functions.BrokerAuthenticationMode authenticationMode
        SASL mechanism to use for authentication. Allowed values: Gssapi, Plain, ScramSha256, ScramSha512 Default: NOTSET
        Returns:
        The broker authentication mode.
        Default:
        com.microsoft.azure.functions.BrokerAuthenticationMode.NOTSET
      • username

        java.lang.String username
        SASL username with the PLAIN and SASL-SCRAM-.. mechanisms Default: ""
        Returns:
        The SASL username.
        Default:
        ""
      • password

        java.lang.String password
        SASL password with the PLAIN and SASL-SCRAM-.. mechanisms Default: "" security.protocol in librdkafka
        Returns:
        The SASL password.
        Default:
        ""
      • protocol

        com.microsoft.azure.functions.BrokerProtocol protocol
        Defines the security protocol used to communicate with brokers default is NOTSET
        Returns:
        The security protocol.
        Default:
        com.microsoft.azure.functions.BrokerProtocol.NOTSET
      • sslKeyLocation

        java.lang.String sslKeyLocation
        Path to client's private key (PEM) used for authentication. Default "" ssl.key.location in librdkafka
        Returns:
        The ssl key location.
        Default:
        ""
      • sslCaLocation

        java.lang.String sslCaLocation
        Path to CA certificate file for verifying the broker's certificate. ssl.ca.location in librdkafka
        Returns:
        The path to CA certificate file.
        Default:
        ""
      • sslCertificateLocation

        java.lang.String sslCertificateLocation
        Path to client's certificate. ssl.certificate.location in librdkafka
        Returns:
        The ssl certificate location.
        Default:
        ""
      • sslKeyPassword

        java.lang.String sslKeyPassword
        Password for client's certificate. ssl.key.password in librdkafka
        Returns:
        The ssl key password.
        Default:
        ""
      • avroSchema

        java.lang.String avroSchema
        Avro schema for generic record deserialization default ""
        Returns:
        the avro schema
        Default:
        ""
      • lagThreshold

        int lagThreshold
        Returns:
        Default:
        1000
      • schemaRegistryUrl

        java.lang.String schemaRegistryUrl
        URL for the Avro Schema Registry default ""
        Returns:
        the avro schema registry url
        Default:
        ""
      • schemaRegistryUsername

        java.lang.String schemaRegistryUsername
        Username for the Avro Schema Registry default ""
        Returns:
        the avro schema registry username
        Default:
        ""
      • schemaRegistryPassword

        java.lang.String schemaRegistryPassword
        Password for the Avro Schema Registry default ""
        Returns:
        the avro schema registry password
        Default:
        ""