Skip to content

Latest commit

 

History

History
80 lines (55 loc) · 3.25 KB

File metadata and controls

80 lines (55 loc) · 3.25 KB

.NET Sample Function

Prerequiste

For more details refer to quickstart: Create your first function in Azure using Visual Studio

This sample will work not only the Windows and Visual Studio. It works on Mac and Linux as well. However, this sample is tested on that enviornment. You can find several way to create a .NET function.

Configuration

A sample function is provided in folder samples/dotnet/KafkaFunctionSample. It depends on the Kafka installed locally (localhost:9092), as described in previous section. Add a local.settings.json files that looks like this:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "None",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "LocalBroker": "localhost:9092"
  }
}

If you have problems connecting to localhost:9092 try to add broker 127.0.0.1 to your host file and use instead of localhost.

Quick Start

You can refer Quick Start on the top page

Test

Restore, Build, and Debug KafkaFunctionSample.

POST request http://localhost:7071/api/ProduceStringTopic with JSON Body and ContentType = application/json.

{"hello":"world"}

EventHubs Sample

Event Hubs provides a Kafka endpoint that can be used by the Kafka extension. For more details, refer to

Configuration

A sample function is provided in samples/dotnet/KafkaFunctionSample/SimpleKafkaTriggers.cs. Follow the direction of Quickstart: Create an event hub using Azure portal Add a local.settings.json files that looks like this:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "None",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "LocalBroker": "YOUR_EVENTHUBS_NAMESPACE.servicebus.windows.net:9093",
    "EHTOPIC": "YOUR_EVENT_HUB_NAME",
    "EventHubConnectionString": "YOUR_EVENTHUBS_CONNECTION_STRING"
  }
}

For more configuration details for EventHubs, refer to the Use Azure Event Hubs from Apache Kafka applications: Shared Access Signature (SAS)

Test

Restore, Build, and Debug KafkaFunctionSample.

POST request http://localhost:7071/api/SampleProducer with raw Body like following.

hello