Annotation Type KafkaOutput


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

    Place this on a parameter whose value would be published to Kafka. 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

    The following example shows a Java function that produce a message to the Kafka cluster, using event provided in the body of an HTTP Post request.

     @FunctionName("kafkaInupt-Java")
    
     public String input(
        @HttpTrigger(name = "request", methods = {HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS)
         final String message,
        @KafkaOutput(name = "event", topic = "users", brokerList="broker:29092") OutputBinding<String< output,
        final ExecutionContext context) {
         context.getLogger().info("Message:" + message);
         output.setValue(message);
         return "{ \"id\": \"" + System.currentTimeMillis() + "\", \"description\": \"" + message + "\" }";
     }
     
    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 name
      The variable name used in function.json.
      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 serialization default ""
      int batchSize
      Defines the maximum number of messages batched in one MessageSet.
      java.lang.String dataType
      Defines how Functions runtime should treat the parameter value.
      boolean enableIdempotence
      When set to `true`, the producer will ensure that messages are successfully produced exactly once and in the original produce order.
      int lingerMs
      linger.MS property provides the time between batches of messages being sent to cluster.
      int maxMessageBytes
      Defines the maximum transmit message size.
      int maxRetries
      How many times to retry sending a failing Message.
      int messageTimeoutMs
      Local message timeout.
      java.lang.String password
      SASL password with the PLAIN and SASL-SCRAM-..
      com.microsoft.azure.functions.BrokerProtocol protocol
      Gets or sets the security protocol used to communicate with brokers default is PLAINTEXT
      int requestTimeoutMs
      The ack timeout of the producer request in milliseconds.
      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.json.
        Returns:
        The variable name used in function.json.
      • topic

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

        java.lang.String brokerList
        Defines the BrokerList.
        Returns:
        The brokerList name string.
      • dataType

        java.lang.String dataType

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

        • "" or string: treat it as a string whose value is serialized from the parameter
        • binary: treat it as a binary data whose value comes from for example OutputBinding<byte[]<
        Returns:
        The dataType which will be used by the Functions runtime.
        Default:
        ""
      • maxMessageBytes

        int maxMessageBytes
        Defines the maximum transmit message size. Default: 1MB
        Returns:
        The maximum trnasmit message size.
        Default:
        1000012
      • batchSize

        int batchSize
        Defines the maximum number of messages batched in one MessageSet. default: 10000
        Returns:
        The maximum number of messages batched in one MessageSet.
        Default:
        10000
      • enableIdempotence

        boolean enableIdempotence
        When set to `true`, the producer will ensure that messages are successfully produced exactly once and in the original produce order. default: false
        Returns:
        whether idempotence is enabled.
        Default:
        false
      • messageTimeoutMs

        int messageTimeoutMs
        Local message timeout. This value is only enforced locally and limits the time a produced message waits for successful delivery. A time of 0 is infinite. This is the maximum time used to deliver a message (including retries). Delivery error occurs when either the retry count or the message timeout are exceeded. default: 300000
        Returns:
        The local message timeout.
        Default:
        300000
      • requestTimeoutMs

        int requestTimeoutMs
        The ack timeout of the producer request in milliseconds. default: 5000
        Returns:
        The ack timeout of the producer request in milliseconds.
        Default:
        5000
      • maxRetries

        int maxRetries
        How many times to retry sending a failing Message. **Note:** default: 2 Retrying may cause reordering unless EnableIdempotence is set to true.
        Returns:
        The number of the max retries.
        See Also:
        enableIdempotence()
        Default:
        2
      • authenticationMode

        com.microsoft.azure.functions.BrokerAuthenticationMode authenticationMode
        SASL mechanism to use for authentication. Default: PLAIN
        Returns:
        The SASL mechanism.
        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 is plaintext security.protocol in librdkafka
        Returns:
        The SASL password.
        Default:
        ""
      • protocol

        com.microsoft.azure.functions.BrokerProtocol protocol
        Gets or sets the security protocol used to communicate with brokers default is PLAINTEXT
        Returns:
        The 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 ssl ca location.
        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:
        ""
      • lingerMs

        int lingerMs
        linger.MS property provides the time between batches of messages being sent to cluster. Larger value allows more batching that results in high throughput.
        Returns:
        value of linger.ms property.
        Default:
        5
      • avroSchema

        java.lang.String avroSchema
        Avro schema for generic record serialization default ""
        Returns:
        the avro schema
        Default:
        ""
      • 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:
        ""