Open mguntli opened 6 years ago
Anyway here is the compiling example with WebJobs & ServiceBus.Messaging, but crashes at startup due to https://github.com/Azure/azure-webjobs-sdk/issues/1565 (System.InvalidOperationException: 'Microsoft.WindowsAzure.Storage is deployed incorrectly)
Program.cs
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.ServiceBus;
using Microsoft.ServiceBus.Messaging;
namespace tutorials {
class Program {
// IoT Hub -> Endpoints -> Built-in endpoints -> Events -> Event Hub-compatible name
private const string eventHubName = "";
// IoT Hub -> Endpoints -> Built-in endpoints -> Events -> Event Hub-compatible endpoint
private const string eventHubConnectionString = "";
private const string eventHubConsumerGroup = "$Default";
private const string storageAccountName = "";
private const string storageAccountKey = "";
private static readonly string storageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountName, storageAccountKey);
public static void Main(string[] args) {
MainAsync(args).GetAwaiter().GetResult();
}
private static async Task MainAsync(string[] args) {
var config = new JobHostConfiguration();
if (config.IsDevelopment) {
config.UseDevelopmentSettings();
}
var eventHubConfig = new EventHubConfiguration();
var eventProcessorHost = new EventProcessorHost(
eventHubName,
eventHubConsumerGroup,
eventHubConnectionString,
storageConnectionString);
eventHubConfig.AddEventProcessorHost(eventHubName, eventProcessorHost);
await eventProcessorHost.RegisterEventProcessorAsync<SimpleEventProcessor>();
config.UseEventHub(eventHubConfig);
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
}
}
SimpleEventProcessor.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ServiceBus.Messaging;
namespace tutorials {
public class SimpleEventProcessor : IEventProcessor {
public Task CloseAsync(PartitionContext context, CloseReason reason) {
Console.WriteLine($"Processor Shutting Down. Partition '{context.RuntimeInfo.PartitionId}', Reason: '{reason}'.");
return Task.CompletedTask;
}
public Task OpenAsync(PartitionContext context) {
Console.WriteLine($"SimpleEventProcessor initialized. Partition: '{context.RuntimeInfo.PartitionId}'");
return Task.CompletedTask;
}
public Task ProcessEventsAsync(PartitionContext context, IEnumerable<EventData> messages) {
foreach (var eventData in messages) {
var data = Encoding.UTF8.GetString(eventData.GetBytes());
Console.WriteLine($"Message received. Partition: '{context.RuntimeInfo.PartitionId}', Data: '{data}'");
}
return context.CheckpointAsync();
}
}
}
You may be mixing .NET Standard Event Hubs documentation with .NET Framework 4.6 WebJobs libraries.
I don't see a quickstart for it anywhere, but some EventProcessorHost APIs for the .NET Framework can be found here: https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-framework-api-overview#event-processor-host-apis
The existing tutorials totally don't match together at all.
Repro steps
VS2017 with latest updates (as of 9th of February 2018)
File -> New -> Project -> Visual C# -> Cloud -> Azure WebJob (.NET Framework)
Manage NuGet Packages -> Update 10 outdated packages
After previous update of 10 packages, update another 8 outdated packages
Add reference to Microsoft.Azure.WebJobs.ServiceBus
You get it, after adding the ServiceBus reference update 2 more outdated packages
Follow the documentation to create your own advanced EventProcessor https://github.com/Azure/azure-webjobs-sdk/wiki/EventHub-support#configuration
Follow the documentation to create your own event processor https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-dotnet-standard-getstarted-receive-eph
It does not match together at all
Expected behavior
There exists a complete tutorial how to consume events from event hubs as continuous WebJob.
Actual behavior
Tutorials don't match together at all. Besides that, the "ProcessErrorAsync" does not exist at all. Besides that, who do you expect to understand the total mess of storage account connection strings? Do we now have to create a separate storage account for every little detail? Are you aware of that the naming of the storage accounts is really horrible (3-27 lower case characters and numbers)
Microsoft, seriously?
Known workarounds
Related information
Provide any related information