static void Main() { ConfigureLogger(); // MassTransit to use Log4Net Log4NetLogger.Use(); IBusControl busControl = CreateBus(); TaskUtil.Await(() => busControl.StartAsync()); try { IRequestClient <ISimpleRequest, ISimpleResponse> client = CreateRequestClient(busControl); for (;;) { Console.Write("Enter customer id (quit exits): "); string customerId = Console.ReadLine(); if (customerId == "quit") { break; } // this is run as a Task to avoid weird console application issues Task.Run(async() => { ISimpleResponse response = await client.Request(new SimpleRequest(customerId)); Console.WriteLine("Customer Name: {0}", response.CusomerName); }).Wait(); } } catch (Exception ex) { Console.WriteLine("Exception!!! OMG!!! {0}", ex); } finally { busControl.Stop(); } }
static void Main() { ConfigureLogger(); Log4NetLogger.Use(); IBusControl busControl = CreateBus(); try { TaskUtil.Await(() => busControl.StartAsync()); IRequestClient <ISimpleRequest, ISimpleResponse> client = busControl.CreateRequestClient(); for (;;) { Console.Write("Enter customer id (quit exits): "); string customerId = Console.ReadLine(); if (customerId == "quit") { break; } Task.Run(async() => { var response = await client.Request(new SimpleRequest(customerId)); Console.WriteLine("Customer Name: {0}", response.CusomerName); }).Wait(); } } catch (Exception ex) { Console.WriteLine(ex); } finally { busControl.Stop(); } Console.ReadLine(); }
static void Main(string[] args) { ConfigureLogger(); Log4NetLogger.Use(); var busControl = CreateBus(); busControl.Start(); try { var client = CreateRequestClient(busControl); while (true) { Console.Write("Enter number: (quit exits): "); string input = Console.ReadLine(); if (input == "quit") { break; } var number = int.Parse(input); Task.Run(async() => { var response = await client.Request(new Request(number)); Console.WriteLine(string.Format("New number = {0}", response.NewNumber)); }).Wait(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { busControl.Stop(); } }
static void Main(string[] args) { ConfigureLogger(); Log4NetLogger.Use(); var busControl = CreateBus(); busControl.Start(); try { while (true) { Console.Write("Enter number: (quit exits): "); string input = Console.ReadLine(); if (input == "quit") { break; } var number = int.Parse(input); Task.Run(async() => { await busControl.Publish <NumberUpdated>(new NumberUpdatedEvent(number)); }).Wait(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { busControl.Stop(); } }
static void Main() { ConfigureLogger(); // MassTransit to use Log4Net Log4NetLogger.Use(); IBusControl busControl = CreateBus(); busControl.StartAsync().Wait(); string validateQueueName = ConfigurationManager.AppSettings["ValidateActivityQueue"]; Uri validateAddress = _host.GetSendAddress(validateQueueName); string retrieveQueueName = ConfigurationManager.AppSettings["RetrieveActivityQueue"]; Uri retrieveAddress = _host.GetSendAddress(retrieveQueueName); try { for (;;) { Console.Write("Enter an address (quit exits): "); string requestAddress = Console.ReadLine(); if (requestAddress == "quit") { break; } if (string.IsNullOrEmpty(requestAddress)) { requestAddress = "http://www.microsoft.com/index.html"; } int limit = 1; if (requestAddress.All(x => char.IsDigit(x) || char.IsPunctuation(x))) { string[] values = requestAddress.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); requestAddress = values[0]; if (values.Length > 1) { limit = int.Parse(values[1]); Console.WriteLine("Sending {0}", limit); } } switch (requestAddress) { case "0": requestAddress = "http://www.microsoft.com/index.html"; break; case "1": requestAddress = "http://i.imgur.com/Iroma7d.png"; break; case "2": requestAddress = "http://i.imgur.com/NK8eZUe.jpg"; break; } Uri requestUri; try { requestUri = new Uri(requestAddress); } catch (UriFormatException) { Console.WriteLine("The URL entered is invalid: " + requestAddress); continue; } IEnumerable <Task> tasks = Enumerable.Range(0, limit).Select(x => Task.Run(async() => { var builder = new RoutingSlipBuilder(NewId.NextGuid()); builder.AddActivity("Validate", validateAddress); builder.AddActivity("Retrieve", retrieveAddress); builder.SetVariables(new { RequestId = NewId.NextGuid(), Address = requestUri, }); RoutingSlip routingSlip = builder.Build(); await busControl.Publish <RoutingSlipCreated>(new { TrackingNumber = routingSlip.TrackingNumber, Timestamp = routingSlip.CreateTimestamp, }); await busControl.Execute(routingSlip); })); Task.WaitAll(tasks.ToArray()); } } catch (Exception ex) { Console.WriteLine("Exception!!! OMG!!! {0}", ex); Console.ReadLine(); } finally { busControl.Stop(); } }