private void GenerateAction(EventHubElement eventHub) { // Event hub client var eventHubHelper = new EventHubHelper(eventHub.EventHubName, eventHub.ConnectionString); // Send order to event hub var order = GenerateOrder(eventHub.Region); Console.WriteLine($"Sending order message to {eventHub.Region}"); eventHubHelper.SendMessageToEventHub(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(order))).GetAwaiter().GetResult(); // Close connection eventHubHelper.CloseEventHub().GetAwaiter().GetResult(); }
public async void DoWork() { try { int loop = 1; var eventHubs = EventHubs; EventHubElement eventHub = eventHubs.First(); //loop... while (true) { //Thread.Sleep(50); if (eventHubs.Count > 1) { if ((loop % 2 == 0)) { eventHub = eventHubs[1]; } else { eventHub = eventHubs.First(); } } GenerateAction(eventHub); loop++; } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.ResetColor(); Console.ReadLine(); } }