6

Trying to follow @matthoneycutt 's tutorial on Azure IoT Hub it seems like Microsoft.Azure.WebHosts.JobHostConfiguration vanished between 3.0.0-beta5 and 3.0.0-rc1 releases of Microsoft.Azure.WebHosts.Host in the Microsoft.Azure.WebHosts nuget package?

What would be the approach to get this code up running in 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();

Seems related to this post, though in a different context

noontz
  • 1,782
  • 20
  • 29

1 Answers1

3

You should be able to do that thru the AddEventHubs extension methods (available in Microsoft.Azure.WebJobs.Extensions.EventHubs package)

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);
                })
Julien Jacobs
  • 2,561
  • 1
  • 24
  • 34
  • Could you provide more information about your configuration please? Are you using v3.0.0 or a pre-release? I cannot see `AddAzureStorageCoreServices` when I try this. – Aaron Sep 29 '18 at 13:46
  • Nevermind; I was able to get it working by uninstalling and reinstalling Microsoft.Azure.WebJobs 3.0.0. – Aaron Sep 29 '18 at 13:53
  • @Aaron I would like to mark this as the answer if I can confirm it works, but I can't locate IWebJobsBuilder.AddAzureStorageCoreServices in the Microsoft.Azure.WebJobs 3.0.0 nuget package. Could you specify uninstalling / reinstalling Microsoft.Azure.WebJobs? – noontz Oct 09 '18 at 07:55
  • @noontz You need to add the Microsoft.Azure.WebJobs.Extensions.Storage nuget package @ https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.Storage – Julien Jacobs Oct 09 '18 at 10:45
  • @JulienJacobs Sorry for the late reply. I still have the same issue as before regarding AddAzureStorageCoreServices() not being available on IWebJobsBuilder. Currently on Microsoft.Azure.WebJobs 3.0.1 – noontz Nov 07 '18 at 09:28
  • 1
    @noontz maybe try to also add package "Microsoft.Azure.WebJobs.Extensions" – Julien Jacobs Nov 07 '18 at 17:37
  • @JulienJacobs Thanks..That solved it.. Consider updating your answer with the required packages ;) – noontz Nov 09 '18 at 07:44