public Boolean SendMessage(TradeQueueMessage <Trade> tradeMessage) { MessageQueue messageQueue = null; if (!MessageQueue.Exists(TradeQueueName)) { messageQueue = MessageQueue.Create(TradeQueueName); } else { messageQueue = new MessageQueue(TradeQueueName); } try { messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(TradeQueueMessage <Trade>) }); messageQueue.Send(tradeMessage); } catch (Exception e) { return(false); } finally { messageQueue.Close(); } return(true); } //Send TradeMessage to Queue
public void AddNotification(Trade trade) { TradeQueueMessage <Trade> tradeMessage = new TradeQueueMessage <Trade>("Trade Added", trade); tradeQueue.SendMessage(tradeMessage); ChangePrice(trade, TypeOfFunction.Add); } //Notification for Trade Addition
} //Notification for Trade Updation public void DeleteNotification(Trade trade) { TradeQueueMessage <Trade> tradeMessage = new TradeQueueMessage <Trade>("Trade Deleted", trade); tradeQueue.SendMessage(tradeMessage); ChangePrice(trade, TypeOfFunction.Delete); } //Notification for Trade Deletion
public IHttpActionResult GetTradeNotification() { TradeQueueMessage <Trade> genericTrade = tradeQueue.ReceiveMessage(); genericTrade.Object = db.Trades.Find(genericTrade.Object.Id); return(Ok(genericTrade)); } // Get trade message from Queue
public void Test_SendMessage() { Trade trade = new Trade(); Guid guid = Guid.NewGuid(); trade.Id = new Guid(); trade.Side = 0; trade.Status = 0; trade.UserId = new Guid(); trade.CommodityId = new Guid(); trade.LocationId = new Guid(); trade.Price = 1000; trade.Quantity = 20; TradeQueueMessage <Trade> tradeQueueMessage = new TradeQueueMessage <Trade>("added", trade); TradeMQueue tradeMQueue = new TradeMQueue(); Boolean actual = tradeMQueue.SendMessage(tradeQueueMessage); Assert.IsTrue(actual); }
} //Send TradeMessage to Queue public TradeQueueMessage <Trade> ReceiveMessage() { if (!MessageQueue.Exists(TradeQueueName)) { return(null); } MessageQueue messageQueue = new MessageQueue(TradeQueueName); TradeQueueMessage <Trade> trade = null; try { messageQueue.Formatter = new XmlMessageFormatter(new Type[] { typeof(TradeQueueMessage <Trade>) }); trade = (TradeQueueMessage <Trade>)messageQueue.Receive().Body; } catch { return(null); } finally { messageQueue.Close(); } return(trade); } // Recieve Trade Message From Queue