如何在 WebJob 中指定 EventHub Consumer Group?
How to specify EventHub Consumer Group in a WebJob?
我正在使用 WebJob 与 EventHub 的绑定,如下所述:
https://github.com/Azure/azure-webjobs-sdk/wiki/EventHub-support
虽然 webjob 正在 运行ning,但尝试 运行 同一集线器上的 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)使用相同的 Consumer Group 造成的。
所以我的问题是,如何在我的网络作业中指定不同的消费者组?
我当前的代码如下所示:
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);
}
}
[编辑 - 奖励问题]
我还没有完全掌握Consumer Group的使用和'epoch'嘛。一个消费者组仅限于一个接收者?
EventHubTrigger
有一个可选的 ConsumerGroup
属性 (source)。因此,在此基础上像这样修改触发器:
public class Functions
{
public static void Trigger([EventHubTrigger("%EventHubName%", ConsumerGroup = "MyConsumerGroup")] string message, TextWriter log)
{
log.WriteLine(message);
}
}
我正在使用 WebJob 与 EventHub 的绑定,如下所述: https://github.com/Azure/azure-webjobs-sdk/wiki/EventHub-support
虽然 webjob 正在 运行ning,但尝试 运行 同一集线器上的 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)使用相同的 Consumer Group 造成的。
所以我的问题是,如何在我的网络作业中指定不同的消费者组?
我当前的代码如下所示:
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);
}
}
[编辑 - 奖励问题]
我还没有完全掌握Consumer Group的使用和'epoch'嘛。一个消费者组仅限于一个接收者?
EventHubTrigger
有一个可选的 ConsumerGroup
属性 (source)。因此,在此基础上像这样修改触发器:
public class Functions
{
public static void Trigger([EventHubTrigger("%EventHubName%", ConsumerGroup = "MyConsumerGroup")] string message, TextWriter log)
{
log.WriteLine(message);
}
}