我想将EventHubTrigger与自定义ConsumerGroup一起使用。
使用默认的ConsumerGroup时,代码如下所示:
public static async Task ProcessQueueMessage([EventHubTrigger("%EventHubName%")] TelemetryEvent[] messages, TextWriter log)
{}
EventHubTriggerAttribute
类具有可以设置的ConsumerGroup属性。但是如何?
[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; }
}
答案 0 :(得分:1)
据我所知,如果要在EventHubTrigger中设置ConsumerGroup属性,可以在EventHubTrigger方法中将其设置为参数。
更多细节,您可以参考以下代码:
public static async Task ProcessQueueMessage([EventHubTrigger("Yourhubname", ConsumerGroup = "groupname")] string[] messages, TextWriter log)
{
...
}