Example #1
0
        public static void Main(string[] args)
        {
            var stockMessagerService = new StockMessagerService(sender);
            var stockItem            = new StockItem("ABC", 1, "FCLondon", "DHL");

            Console.WriteLine("Enter batch size to send messages");
            var stockItemBatch = new List <StockItem>();

            string cmd;

            while ((cmd = Console.ReadLine()) != "exit")
            {
                var numberOfMessages = Int32.Parse(cmd);
                for (int i = 0; i < numberOfMessages; i++)
                {
                    //stockMessagerService.SendMessageAsync(stockItem).Wait();
                    stockItemBatch.Add(stockItem);
                }
                stockMessagerService.SendMessageBatchAsync(stockItemBatch).Wait();
                Console.WriteLine($"Message Batch sent");

                stockMessagerService.SendMessageAsync(new StockItem("DEF", 1, "FCWestLondon", "UPS")).Wait();
                Console.WriteLine($"Message with SKU 'DEF' sent");


                stockMessagerService.SendDeadletterMessageAsync(stockItem).Wait();
                Console.WriteLine($"Poisoned Message sent");
            }
        }
Example #2
0
        public void PublishMessageOfStockItem()
        {
            //arrange
            var stockItem            = new StockItem("ABC", 1, "FCLondon", "DHL");
            var stockMessagerService = new StockMessagerService(sender);
            var topicClient          = factory.CreateTopicClient("stocklevels");
            var subscriptionClient   = factory.CreateSubscriptionClient(topicClient.Path, "GBWarehouseStockLevels");

            stockMessagerService.SendMessageAsync(stockItem).Wait();
            var message      = subscriptionClient.Receive();
            var streamReader = new StreamReader(message.GetBody <Stream>());
            var result       = JsonConvert.DeserializeObject <StockItem>(streamReader.ReadToEnd());

            //assert
            Assert.That(result.Sku.Equals("ABC"));
        }