private static void RunTestSeq(EventHubConfig config, string messageBody, int iterations) { var _eventHubListener = new EventHubListener(config); var _eventHubSender = new EventHubSender(config, messageBody, iterations); _eventHubListener.StartListening().GetAwaiter().GetResult(); _eventHubSender.SendMessages().GetAwaiter().GetResult(); }
/// <summary> /// The method that registers Event Hub listeners and assigns them to a Receive event. When I receive an event from the event hub listener, I trigger the callbackURL /// </summary> /// <param name="triggerId"></param> /// <param name="triggerInput"></param> public async Task RegisterTrigger(EventHubInput input) { var client = EventHubClient.CreateFromConnectionString(input.eventHubConnectionString, input.eventHubName); EventHubConsumerGroup group = String.IsNullOrEmpty(input.consumerGroup) ? client.GetDefaultConsumerGroup() : client.GetConsumerGroup(input.consumerGroup); string[] partitions; //If they specified partitions, iterate over their list to only listen to the partitions they specified if (!String.IsNullOrEmpty(input.eventHubPartitionList)) { partitions = input.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(); } } List <CancellationTokenSource> tokenSources = new List <CancellationTokenSource>(); //For ever partition I should listen to, create a thread with a listener on it foreach (var p in partitions) { p.Trim(); var Receiver = group.CreateReceiver(client.GetRuntimeInformation().PartitionIds[int.Parse(p)], DateTime.UtcNow); EventHubListener listener = new EventHubListener(Receiver); //Register the event. When I Receive a message, call the method to trigger the logic app listener.MessageReceived += (sender, e) => TriggerLogicApps(input.callbackUrl, e); var ts = new CancellationTokenSource(); CancellationToken ct = ts.Token; listener.StartListening(ct); tokenSources.Add(ts); } //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[input.callbackUrl] = tokenSources; }
/// <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.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; }
/// <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; }
/// <summary> /// The method that registers Event Hub listeners and assigns them to a Receive event. When I receive an event from the event hub listener, I trigger the callbackURL /// </summary> /// <param name="triggerId"></param> /// <param name="triggerInput"></param> public async Task RegisterTrigger(EventHubInput input) { var client = EventHubClient.CreateFromConnectionString(input.eventHubConnectionString, input.eventHubName); EventHubConsumerGroup group = String.IsNullOrEmpty(input.consumerGroup) ? client.GetDefaultConsumerGroup() : client.GetConsumerGroup(input.consumerGroup); string[] partitions; //If they specified partitions, iterate over their list to only listen to the partitions they specified if (!String.IsNullOrEmpty(input.eventHubPartitionList)) { partitions = input.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(); } } List<CancellationTokenSource> tokenSources = new List<CancellationTokenSource>(); //For ever partition I should listen to, create a thread with a listener on it foreach (var p in partitions) { p.Trim(); var Receiver = group.CreateReceiver(client.GetRuntimeInformation().PartitionIds[int.Parse(p)], DateTime.UtcNow); EventHubListener listener = new EventHubListener(Receiver); //Register the event. When I Receive a message, call the method to trigger the logic app listener.MessageReceived += (sender, e) => TriggerLogicApps(input.callbackUrl, e); var ts = new CancellationTokenSource(); CancellationToken ct = ts.Token; listener.StartListening(ct); tokenSources.Add(ts); } //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[input.callbackUrl] = tokenSources; }