public CustomerReply SendRequest(int cusId, int prodId, string country) { _bus.Receive <OrderReplyMessage>("ReplyQueue" + cusId, message => HandleOrderEvent(message)); CustomerOrderRequestMessage request = new CustomerOrderRequestMessage { CustomerId = cusId, ProductId = prodId, Country = country }; _bus.Send("retailerQueue", request); bool gotReply; lock (this) { // Block this thread so that the Retailer program will not exit. gotReply = Monitor.Wait(this, timeout); } if (gotReply) { return(_replyMessages); } else { return new CustomerReply() { Message = "no reply received" } }; }
public void Start() { SynchronizedWriteLine("Customer running. Waiting for a reply.\n"); CustomerOrderRequestMessage request = new CustomerOrderRequestMessage { SSN = SSN, }; using (IBus bus = RabbitHutch.CreateBus("host=localhost")) { // Listen to reply messages from the Broker bus.Subscribe <BrokerReplyMessage>("customer" + SSN, HandleOrderEvent, x => x.WithTopic(SSN.ToString())); // Send an order request message to the Broker bus.Send <CustomerOrderRequestMessage>("BrokerQueue", request); lock (this) { // Block this thread so that the Customer program will not exit. bool gotReply = Monitor.Wait(this, timeout); if (!gotReply) { SynchronizedWriteLine( "Timeout. The requested loan is not available!"); } } } }
public static CustomerOrderRequestMessage FilterCustomerOrderRequestMessage(CustomerOrderRequestMessage message) { return(new CustomerOrderRequestMessage { SSN = message.SSN }); }
private void HandleOrderRequest(CustomerOrderRequestMessage request) { int SSN = request.SSN; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Request received from customer " + SSN); Console.WriteLine("Trying to send the request to a bank."); Console.ResetColor(); OrderBroadcastRequestMessage requestMessage = MessageTransformers.EnrichOrderRequestMessage(creditScore, historyLength, loanAmount, loanterm, replyQueueName); //outstandingOrderRequests.TryAdd(orderId, requestMessage); //customerIdsForOutstandingOrderRequests.TryAdd(orderId, customerId); //OrderRequestMessageToLocalWarehouse requestMessage = new OrderRequestMessageToLocalWarehouse //{ // ProductId = request.ProductId, // CustomerId = request.CustomerId, // Country = request.Country, // OrderId = ++orderId, // ReplyTo = replyQueueName //}; // Uses Topic Based Routing to send the request to a local warehouse. The topic // is requestMessage.Country. bus.Publish <OrderBroadcastRequestMessage>(requestMessage); }
public string SendRequest(int productID) { CustomerOrderRequestMessage request = new CustomerOrderRequestMessage { CustomerId = customerID, ProductId = productID }; bool gotReply; bus.Send <CustomerOrderRequestMessage>("retailerQueue", request); lock (this) { gotReply = Monitor.Wait(this, timeout); } if (gotReply) { return(replyMessage); } else { throw new Exception("Timeout. The requested product is out of stock!"); } }
public static CustomerOrderRequestMessage FilterCustomerOrderRequestMessage(CustomerOrderRequestMessage message) { return(new CustomerOrderRequestMessage { ProductId = message.ProductId, Country = message.Country }); }
public static OrderRequestMessageToLocalWarehouse EnrichOrderRequestMessage( CustomerOrderRequestMessage message, string replyTo, int orderId) { return(new OrderRequestMessageToLocalWarehouse { ProductId = message.ProductId, Country = message.Country, OrderId = orderId, ReplyTo = replyTo }); }
public OrderReplyMessage PlaceOrder(CustomerOrderRequestMessage request) { bool gotReply; // Send an order request message to the Retailer bus.Send <CustomerOrderRequestMessage>("retailerQueue", request); lock (this) { // Block the thread until a reply is received from the Retailer gotReply = Monitor.Wait(this, timeout); } if (gotReply) { return(reply); } else { throw new Exception("Timeout. The requested product is out of stock!"); } }
private void HandleOrderRequest(CustomerOrderRequestMessage request) { int customerId = request.CustomerId; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Request received from customer " + customerId); Console.WriteLine("Trying to send the request to a local warehouse."); Console.ResetColor(); OrderRequestMessageToLocalWarehouse requestMessage = new OrderRequestMessageToLocalWarehouse { ProductId = request.ProductId, CustomerId = request.CustomerId, Country = request.Country, OrderId = ++orderId, ReplyTo = replyQueueName }; // Uses Topic Based Routing to send the request to a local warehouse. The topic // is requestMessage.Country. bus.Publish <OrderRequestMessageToLocalWarehouse>(requestMessage, requestMessage.Country); }
public EnvelopeRequestMessage WrapMessage(CustomerOrderRequestMessage message) { return(new EnvelopeRequestMessage { Country = message.Country, Message = message }); }