什么是Microsoft.Azure.WebHosts.JobHostConfiguration的替代品

时间:2018-09-18 09:35:29

标签: c# azure azure-webjobs azure-webjobssdk

尝试遵循@matthoneycutttutorial on Azure IoT Hub Microsoft.Azure.WebHosts.JobHostConfiguration在3.0.0-beta5之间消失 Microsoft.Azure.WebHosts nuget程序包中的Microsoft.Azure.WebHosts.Host的3.0.0-rc1版本?

如何使此代码在Microsoft.Azure.WebHosts 3.0.0-rc1中运行?

var processorHost = new EventProcessorHost(hubName, consumerGroupName, iotHubConnectionString, storageConnectionString,storageContainerName);
processorHost.RegisterEventProcessorAsync<LoggingEventProcessor>().Wait();
var eventHubConfig = new EventHubConfiguration();
eventHubConfig.AddEventProcessorHost(hubName, processorHost);
var configuration = new JobHostConfiguration(storageConnectionString);
configuration.UseEventHub(eventHubConfig);
var host = new JobHost(configuration);
host.RunAndBlock();

似乎与this post有关,尽管上下文不同

1 个答案:

答案 0 :(得分:2)

您应该可以通过AddEventHubs扩展方法(在Microsoft.Azure.WebJobs.Extensions.EventHubs包中提供)来做到这一点

var builder = new HostBuilder()
            .ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices()
                .AddAzureStorage()
                .AddEventHubs(eventHubOptions => {
                    var hubName = "hubName";
                    var iotHubConnectionString = "iotHubConnectionString";
                    var storageContainerName = "storageContainerName";
                    var storageConnectionString = "storageConnectionString";
                    var consumerGroupName = "consumerGroupName";

                    var processorHost = new EventProcessorHost(hubName, consumerGroupName, iotHubConnectionString, storageConnectionString, storageContainerName);
                    eventHubOptions.AddEventProcessorHost("eventHubName", processorHost);
                })