Azure / azure-functions-kafka-extension

Kafka extension for Azure Functions
MIT License
114 stars 82 forks source link

For the KafkaTrigger, how can I configure the protocol to be Ssl if I have certs but NotSet if I don't? #348

Open justinmchase opened 2 years ago

justinmchase commented 2 years ago

I have an isolated function with a [KafkaTrigger], how can I set the Protocol dynamically?

[Function("hello_kafka")]
public async Task HelloKafka(
  [KafkaTrigger(
    "%KafkaBootstrapServers%",
    "%KafkaTopicsHelloName%",
    ConsumerGroup = "%KafkaTopicsHelloConsumerGroup%",

    Protocol = BrokerProtocol.NotSet, // How do I dynamically set this?

    // These may be set sometimes, not other times.
    SslCaLocation = "%KafkaSslCaLocation%",
    SslCertificateLocation =  "%KafkaSslCertificateLocation%",
    SslKeyLocation = "%KafkaSslKeyLocation%",
    SslKeyPassword = "%KafkaSslKeyPassword%",
    IsBatched = true
  )]
  string[] inputs)
{
    // todo...
    await Task.CompletedTask;
}

So then I'm setting Values__KafkaSslCaLocation=/path/to/file.crt for example in one environment, which requires a BrokerProtocol.Ssl to be set but in another environment there is no need to to have certs or the broker protocol set... But I can't use a template string like the other fields on the Protocol because it is an enum...

So how can I dynamically configure this trigger differently in different environments for an isolated function?

justinmchase commented 2 years ago

This line of code here appears to be part of the problem: https://github.com/Azure/azure-functions-kafka-extension/blob/320cb5994ce259d012ff7b1128bd515946e03164/src/Microsoft.Azure.WebJobs.Extensions.Kafka/Trigger/KafkaTriggerAttributeBindingProvider.cs#L115

It only seems to set it directly from the attribute and there is no extension for pulling it out of configuration. The only way to set it onto the attribute appears to be statically... so how can this be done?

fabiocav commented 2 years ago

@justinmchase transferring this to the Kafka extension repo as folks here will be able to triage this and provide guidance/take action. Thanks!