我正在使用WebJob与EventHub的绑定,如下所述:https://github.com/azure/azure-webjobs-sdk/wiki/eventhub-support
在WebJob运行时,试图在同一集线器上运行Azure Service Bus Explorer在此例外情况下:
Exception: A receiver with a higher epoch '14' already exists. A new receiver with epoch 0 cannot be created.
Make sure you are creating receiver with increasing epoch value to ensure connectivity, or ensure all old epoch receivers are closed or disconnected.
据我了解,这是由使用同一消费者组的2个听众(WebJob& Bus Explorer)引起的。
所以我的问题,如何在我的WebJob中指定另一个消费者组?
我当前的代码看起来像这样:
program.cs:
var config = new JobHostConfiguration()
{
NameResolver = new NameResolver()
};
string eventHubConnectionString = ConfigurationManager.ConnectionStrings["EventHub"].ConnectionString;
string eventHubName = ConfigurationManager.AppSettings["EventHubName"];
string eventProcessorHostStorageConnectionString = ConfigurationManager.ConnectionStrings["EventProcessorHostStorage"].ConnectionString; ;
var eventHubConfig = new EventHubConfiguration();
eventHubConfig.AddReceiver(eventHubName, eventHubConnectionString, eventProcessorHostStorageConnectionString);
config.UseEventHub(eventHubConfig);
var host = new JobHost(config);
host.RunAndBlock();
functions.cs:
public class Functions
{
public static void Trigger([EventHubTrigger("%EventHubName%")] string message, TextWriter log)
{
log.WriteLine(message);
}
}
[编辑 - 奖励问题]
我没有完全掌握消费者组和"时代"的使用。一个消费者组仅限于一个接收器?
EventHubTrigger
具有可选的ConsumerGroup
属性(源)。因此,基于这样的修改触发器:
public class Functions
{
public static void Trigger([EventHubTrigger("%EventHubName%", ConsumerGroup = "MyConsumerGroup")] string message, TextWriter log)
{
log.WriteLine(message);
}
}