static void Main() { var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.Host("rabbitmq://localhost", hostConfigurator => { hostConfigurator.Username("admin"); hostConfigurator.Password("admin"); }); cfg.OverrideDefaultBusEndpointQueueName("OrderRegistration-PublisherExchange"); }); bus.Start(); var orderRegisteredMessage = new OrderRegistered { OrderId = 1, OrderDate = DateTime.Now, CustomerNumber = DateTime.Now.Millisecond.ToString(), }; var requestClient = bus.CreateRequestClient <OrderRegistered>(RequestTimeout.After(s: 5)); var response = requestClient.GetResponse <OrderAccepted, OrderRejected>(orderRegisteredMessage).Result; //DO Some thing with response. Console.ReadKey(); bus.Stop(); }
private void Consume(IRegisterOrder command) { //Store order registration and get Id var id = 12; Console.WriteLine($"Order with id {id} registered"); Console.WriteLine("Publishing order registered event"); //notify subscribers that a order is registered var orderRegisteredEvent = new OrderRegistered(command, id); //publish event rabbitMqManager.SendOrderRegisteredEvent(orderRegisteredEvent); }
static void Main(string[] args) { Array orderTypes = Enum.GetValues(typeof(OrderType)); Random random = new Random(); for (int i = 0; i < 1000; i++) { OrderType randomOrderType = (OrderType)orderTypes.GetValue(random.Next(orderTypes.Length)); var message = new OrderRegistered( Guid.NewGuid(), random.Next(1, 10).ToString(), randomOrderType, (decimal)random.Next(1, 10), (decimal)random.Next(1, 10)); _messagePublisher.PublishMessageAsync(MessageTypes.RegisterOrder, message, ""); Thread.Sleep(1000); } }
static void Main() { var bus = Bus.Factory.CreateUsingRabbitMq(config => { config.Host("rabbitmq://localhost:5672/", hc => { hc.Username("guest"); hc.Password("guest"); }); }); bus.Start(); var rnd = new Random(); var order = new OrderRegistered { OrderId = rnd.Next(1, 10), CustomerNumber = rnd.Next(10, 100).ToString(), OrderDate = DateTime.Now, }; var(acceptResponse, rejectResponse) = bus.CreateRequestClient <OrderRegistered>() .GetResponse <OrderAccepted, OrderRejected>(order).Result; if (acceptResponse.IsCompleted) { Console.WriteLine("accepted!"); Console.WriteLine(acceptResponse.Result.Message); } else { Console.WriteLine("rejected!"); Console.WriteLine(rejectResponse.Result.Message); } Console.ReadKey(); bus.Stop(); }
private async Task <bool> HandleAsync(OrderRegistered e) { Console.WriteLine("Order was registered"); return(true); }