private void ConfigureEventHubProcessor() { // Read from the default consumer group: $Default string consumerGroup = EventHubConsumerClient.DefaultConsumerGroupName; string _blobStorageConnectionString = Configuration["AzureBlob:ConnectionString"]; string _blobContainerName = Configuration["AzureBlob:ContainerName"]; string _ehubNamespaceConnectionString = Configuration["EventHub:ConnectionString"]; string _eventHubName = Configuration["EventHub:Name"]; // Create a blob container client that the event processor will use BlobContainerClient storageClient = new BlobContainerClient(_blobStorageConnectionString, _blobContainerName); // Create an event processor client to process events in the event hub _processor = new EventProcessorClient(storageClient, consumerGroup, _ehubNamespaceConnectionString, _eventHubName); _processor.ProcessEventAsync += _processor_ProcessEventAsync; _processor.ProcessErrorAsync += _processor_ProcessErrorAsync; _processor.StartProcessing(); }
private void InitEventHubProcessor(EventHubConnection eventHubConnection) { if (eventHubConnection == null) { throw new ArgumentNullException(nameof(eventHubConnection)); } if (string.IsNullOrEmpty(eventHubConnection.EventHubConnectionString)) { throw new ArgumentNullException(nameof(eventHubConnection.EventHubConnectionString)); } if (string.IsNullOrEmpty(eventHubConnection.EventHubName)) { throw new ArgumentNullException(nameof(eventHubConnection.EventHubName)); } if (string.IsNullOrEmpty(eventHubConnection.StorageConnectionString)) { throw new ArgumentNullException(nameof(eventHubConnection.StorageConnectionString)); } if (string.IsNullOrEmpty(eventHubConnection.StorageContainerName)) { throw new ArgumentNullException(nameof(eventHubConnection.StorageContainerName)); } string consumerGroup = string.IsNullOrEmpty(eventHubConnection.EventHubConsumerGroup) ? EventHubConsumerClient.DefaultConsumerGroupName : eventHubConnection.EventHubConsumerGroup; var storageClient = new BlobContainerClient(connectionString: eventHubConnection.StorageConnectionString, blobContainerName: eventHubConnection.StorageContainerName); _eventProcessorClient = new EventProcessorClient(checkpointStore: storageClient, consumerGroup: consumerGroup, connectionString: eventHubConnection.EventHubConnectionString, eventHubName: eventHubConnection.EventHubName); _eventProcessorClient.ProcessEventAsync += ProcessEventHandler; _eventProcessorClient.ProcessErrorAsync += ProcessErrorHandler; _eventProcessorClient.StartProcessing(); }
private void StartEventHubReciever(string eventHubName, string consumerGroup) { cts = new System.Threading.CancellationTokenSource(); var b = new BlobContainerClient(Connections.StorageConnectionString, StorageContainerName); var e = new EventProcessorClient(b, consumerGroup, Connections.EventHubConnectionString, eventHubName); e.ProcessEventAsync += (ProcessEventArgs eventArgs) => { System.Console.WriteLine("Recieved data"); ehMsgQueue.Enqueue(eventArgs.Data); return(Task.CompletedTask); }; e.ProcessErrorAsync += (ProcessErrorEventArgs eventArgs) => { System.Console.WriteLine(eventArgs.Exception.Message); return(Task.CompletedTask); }; e.StartProcessing(cts.Token); }