如何在WebJob中指定EventHub使用者组?

问题描述 投票:0回答:1

我正在使用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和总线浏览器)引起的。

所以我的问题是,如何在我的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);
        }
    }

[编辑 - 奖金问题]

我没有完全掌握消费者群体的使用和“时代”的事情。一个消费者群体仅限一个接收者?

azure-webjobs azure-eventhub azure-webjobssdk
1个回答
0
投票

EventHubTrigger有一个可选的ConsumerGroup属性(source)。所以,基于此修改触发器如下:

    public class Functions
    {
        public static void Trigger([EventHubTrigger("%EventHubName%", ConsumerGroup = "MyConsumerGroup")] string message, TextWriter log)
        {
            log.WriteLine(message);
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.