Adding a KafkaTrigger function crashes at startup with Value cannot be null. (Parameter 'provider') error

689 views Asked by At

I added this one single, specific reference:

<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Kafka" Version="3.3.2" />

I'm able to add this one function to recieve the error, and comment it out to have it go away:

[Function("hello_kafka")]
public async Task HelloKafka(
  [KafkaTrigger(
    "localhost:9092",
    "hello",
    ConsumerGroup = "hello"
  )]
  string input,
  FunctionContext context)
{
    Console.WriteLine(input);
    await Task.CompletedTask;
}

Here is the actual error:

Function Runtime Version: 4.0.1.16815

A host error has occurred during startup operation '4ce2502e-0d06-4e59-be75-2606b814812a'. Confluent.Kafka: Failed to load the librdkafka native library. Value cannot be null. (Parameter 'provider')

error MSB3073: The command "func host start" exited with code 1.

1

There are 1 answers

0
justin.m.chase On

This was brutal but the answer is that its just straight up not loading the binary correctly and after digging through the docs it appears I had to add this environment variable:

LD_LIBRARY_PATH=/path/to/code/bin/Debug/net6.0/.azurefunctions/runtimes/linux-x64/native

Docker Compose Example

  myapp:
    image: ${DOCKER_REGISTRY-}myapp
    build:
      context: .
      dockerfile: ./MyApp/Dockerfile  
    environment:
        AZURE_FUNCTIONS_ENVIRONMENT: Development
        LD_LIBRARY_PATH: /home/site/wwwroot/bin/Debug/net6.0/runtimes/linux-x64/native

Note: the base path /home/site/wwwroot/ corresponds to the default WORKDIR within the Dockerfile generated by Visual Studio, but this path may differ for custom Dockerfile builds.