0

I would like to use the EventHubTrigger with a custom ConsumerGroup.

The code looks like this when using the default ConsumerGroup:

public static async Task ProcessQueueMessage([EventHubTrigger("%EventHubName%")] TelemetryEvent[] messages, TextWriter log)
        {}

The EventHubTriggerAttribute class has a ConsumerGroup property which can be set. But how?

[AttributeUsage(AttributeTargets.Parameter)]
public sealed class EventHubTriggerAttribute : Attribute
{
    //
    // Summary:
    //     Create an instance of this attribute.
    //
    // Parameters:
    //   eventHubName:
    //     Event hub to listen on for messages.
    public EventHubTriggerAttribute(string eventHubName);

    //
    // Summary:
    //     Name of the event hub.
    public string EventHubName { get; }
    //
    // Summary:
    //     Optional Name of the consumer group. If missing, then use the default name, "$Default"
    public string ConsumerGroup { get; set; }
}
Pascal Naber
  • 1,092
  • 8
  • 14

1 Answers1

1

As far as I know, if you want to set ConsumerGroup property in EventHubTrigger, you could set it as parameter in the EventHubTrigger method.

More details, you could refer to follow codes:

    public static async Task ProcessQueueMessage([EventHubTrigger("Yourhubname", ConsumerGroup = "groupname")] string[] messages, TextWriter log)
    {
       ...
    }
Brando Zhang
  • 22,586
  • 6
  • 37
  • 65