Pascal Naber
Pascal Naber

Reputation: 1092

Configure custom ConsumerGroup using EventHubTrigger

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; }
}

Upvotes: 0

Views: 474

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28397

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)
    {
       ...
    }

Upvotes: 1

Related Questions