Announcing Azure Functions Kafka extension Public Preview
Tags: azure, serverless, kafka
Published: 2020-04-28 04:38:18

We're excited to announce today the public preview of the [Kafka Extension](https://github.com/Azure/azure-functions-kafka-extension) for Azure Functions. With this new extension you can now have functions trigger in response to messages in Kafka Topics, or write to a Kafka Topic through the output binding. The extension is supported when hosting functions in the [Premium plan](https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale#premium-plan) enabling it to elastically scale and trigger on Kafka messages. You can also use Kafka with Azure Functions containers in Kubernetes alongside [KEDA](https://keda.sh/scalers/apache-kafka/) 

### How to get started with the Kafka Trigger
To get started with using the Kafka trigger, you need to include the extension in your function project.

#### .NET Functions
For .NET functions, you can pull in the Kafka [NuGet extension](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Kafka/2.0.0-beta).
```
dotnet add package Microsoft.Azure.WebJobs.Extensions.Kafka --version 2.0.0-beta
```

#### JavaScript, TypeScript, Python, Java, and PowerShell Functions
For other functions, you need to install the extension into your project using the Azure Functions core tools
```
func extensions install Microsoft.Azure.WebJobs.Extensions.Kafka --version 2.0.0-beta
```

You can then create a function that can activate and run whenever a message is dropped in a  Kafka topic.

### Example C# Trigger using Confluent Cloud Managed Kafka 

```c#
public static class kafka_example
    {
        [FunctionName("kafkaApp")]
        public static void ConfluentCloudStringTrigger(
             [KafkaTrigger(
                "BootstrapServer",
                "users",
                ConsumerGroup = "<ConsumerGroup>",
                Protocol = BrokerProtocol.SaslSsl,
                AuthenticationMode = BrokerAuthenticationMode.Plain,
                Username = "<APIKey>",
                Password = "<APISecret>",
                SslCaLocation = "confluent_cloud_cacert.pem")]
        KafkaEventData<string> kafkaEvent,
        ILogger logger)
        {	    
            logger.LogInformation(kafkaEvent.Value.ToString());
        }
    }
```

### Example host.json

```json
{
  "version": "2.0",
  "extensions": {
    "kafka": {
      "maxBatchSize": 100
    }
  }
}
```
You can find more settings documented [here](https://github.com/Azure/azure-functions-kafka-extension#configuration-settings)

### Example functions.json
Note: This is auto-generated for C#
```json
{
  
  "bindings": [
    {
      "type": "kafkaTrigger",
      "consumerGroup": "azfunc",
      "protocol": "saslSsl",
      "authenticationMode": "plain",
      "username": "<KafkaAPIKey>",
      "password": "<KakfaSecret>",
      "sslCaLocation": "<RootCertificateFile>",
      "topic": "<KafkaTopicName>",
      "brokerList": "<Server>.eastus.azure.confluent.cloud:9092",
      "name": "kafkaEvent"
    }
  ],
  
}
```
Please find a complete end to end walkthrough and sample app using the Confluent Cloud in this GitHub repo [Kafka extension sample with Confluent Cloud.](https://github.com/Azure/azure-functions-kafka-extension-sample-confluent)

This extension is being developed in the open, please contribute, try out and post any issues on the [Azure Functions Kafka extension GitHub repo](https://github.com/Azure/azure-functions-kafka-extension).

Along with the [Rabbit MQ Trigger](https://dev.to/azure/announcing-the-rabbitmq-extension-for-azure-functions-2mbo) that we announced last year that is now also supported in the Premium Plan, we continue to innovate to bring in more Cloud Native and Open Source event sources. We are looking forward to see what applications you build with this !