Skip to content

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

@shaunco

Description

@shaunco

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,

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions