/// <summary> /// The method that registers Event Hub listeners and assigns them to a recieve event. When I receive an event from the event hub listener, I trigger the callbackURL /// </summary> /// <param name="triggerId"></param> /// <param name="triggerInput"></param> /// <returns></returns> public async Task RegisterTrigger(string triggerId, TriggerInput<EventHubInput, EventHubMessage> triggerInput) { var client = EventHubClient.CreateFromConnectionString(triggerInput.inputs.eventHubConnectionString, triggerInput.inputs.eventHubName); EventHubConsumerGroup group = client.GetDefaultConsumerGroup(); //client.GetConsumerGroup(triggerInput.inputs.consumerGroup); string[] partitions; //If they specified partitions, iterate over their list to only listen to the partitions they specified if (!String.IsNullOrEmpty(triggerInput.inputs.eventHubPartitionList)) { partitions = triggerInput.inputs.eventHubPartitionList.Split(','); } //If they left it blank, create a list to listen to all partitions else { partitions = new string[client.GetRuntimeInformation().PartitionCount]; for(int x = 0; x < partitions.Length; x++) { partitions[x] = x.ToString(); } } //For ever partition I should listen to, create a thread with a listener on it foreach (var p in partitions) { p.Trim(); var reciever = group.CreateReceiver(client.GetRuntimeInformation().PartitionIds[int.Parse(p)], DateTime.UtcNow); EventHubListener listener = new EventHubListener(reciever); //Register the event. When I recieve a message, call the method to trigger the logic app listener.MessageReceived += (sender, e) => sendTrigger(sender, e, Runtime.FromAppSettings(), triggerInput.GetCallback()); listener.StartListening(); } //Register the triggerID in my store, so on subsequent checks from the logic app I don't spin up a new set of listeners _store[triggerId] = true; }