azure-functions-kafka-extension icon indicating copy to clipboard operation
azure-functions-kafka-extension copied to clipboard

C# KafkaTriggerAttribute and KafkaAttribute should accept strings for Protocol and AuthenticationMode

Open shaunco opened this issue 5 years ago • 1 comments

C# requires that attribute arguments must be a constant expression, typeof expression, or array creation expression of an attribute parameter type, which makes putting the Protocol and AuthenticationMode arguments for both KafkaTriggerAttribute and KafkaAttribute in to *.settings.json files impossible.

In code you can do something like:

BrokerProtocol protocol = (BrokerProtocol)Enum.Parse(typeof(BrokerProtocol), @"%Sec_Protocol%");

but, that doesn't work for Attribute arguments.

It would be fantastic if KafkaTriggerAttribute and KafkaAttribute added string attribute versions of Protocol and AuthenticationMode that internally do the Enum.Parse() so that these values can be populated as:

[KafkaTrigger(@"%Broker%",
              @"%TopicName%",
              SslCaLocation = @"%CaFile%",
              Protocol = @"%Protocol%",              // <-----
              AuthenticationMode = @"%AuthMode%",    // <-----
              Username = @"%Username%",
              Password = @"%Password%",
              ConsumerGroup = "%ConsumerGroup%" )] KafkaEventData<byte[]>[] events,

instead of hardcoded like:

[KafkaTrigger(@"%Broker%",
              @"%TopicName%",
              SslCaLocation = @"%CaFile%",
              Protocol = BrokerProtocol.SaslSsl,                      // <-----
              AuthenticationMode = BrokerAuthenticationMode.Plain,    // <-----
              Username = @"%Username%",
              Password = @"%Password%",
              ConsumerGroup = "%ConsumerGroup%" )] KafkaEventData<byte[]>[] events,

shaunco avatar Aug 16 '20 05:08 shaunco

Hi, any update ? I would like to get rid of those #if DEBUG when testing with a local broker...

arkiaconsulting avatar Aug 27 '21 15:08 arkiaconsulting

No this requirement doesn't make sense as we would like to bound customers to only use the supported protocols. If there is any protocol which is not supported feel free to raise the issue or PR we will work on that.

shrohilla avatar Dec 14 '22 04:12 shrohilla

No this requirement doesn't make sense as we would like to bound customers to only use the supported protocols. If there is any protocol which is not supported feel free to raise the issue or PR we will work on that.

@shrohilla I don't understand your answer. The requirement is not about supporting other protocols, but to be able to parameterize the protocol more easily. For instance, we don't want to run a fully configured cluster locally to run functional tests. So those KafkaTrigger properties should be configurable as any other standard configuration setting.

arkiaconsulting avatar Dec 14 '22 08:12 arkiaconsulting

Seconding what @arkiaconsulting said. This really should not have been closed - especially not as "completed".

shaunco avatar Jan 07 '23 09:01 shaunco

Hi, any update about send configs AuthenticationMode and Protocol as expression instead of enums ?

milhati10 avatar Aug 31 '23 19:08 milhati10