public void PerformanceTest()
        {
            int BACKLOG = 1000;

            // Seed the queue with a backlog.
            CreateTempDirs();
            FileSystemNotificationQueue Q = new FileSystemNotificationQueue
                                                (INBOX_DIR, INPROCESS_DIR, SUCCESS_DIR, FAILURE_DIR);

            for (int i = 0; i < BACKLOG; i++)
            {
                Q.Send(new NotificationQueueMessage(GetRandomId(), GetRandomType(), GetRandomOrderId(), XML));
            }
            // Sleep 30 seconds to make sure the notification files are old enough.
            Thread.Sleep(30000);
            // Run the actual test.
            DateTime StartTime = DateTime.Now;

            for (int i = 0; i < BACKLOG; i++)
            {
                Q.Send(new NotificationQueueMessage(GetRandomId(), GetRandomType(), GetRandomOrderId(), XML));
                NotificationQueueMessage M = Q.Receive();
                Q.ProcessingSucceeded(M);
            }
            TimeSpan Duration = DateTime.Now.Subtract(StartTime);

            Console.WriteLine("Took {0} seconds to catch up with a backlog of {1} messages, while new ones were being added.", Duration.TotalSeconds, BACKLOG);
            Console.WriteLine("Throughput: {0} messages per second.", BACKLOG / Duration.TotalSeconds);
        }
 public void Create()
 {
     string Id = "85f54628-538a-44fc-8605-ae62364f6c71";
       string Type = "order-state-change-notification";
       string OrderId = "841171949013218";
       string Xml = "<a>blah</a>\n<b>blah</b>";
       NotificationQueueMessage M = new NotificationQueueMessage(Id, Type, OrderId, Xml);
       Assert.AreEqual(Id, M.Id);
       Assert.AreEqual(Type, M.Type);
       Assert.AreEqual(OrderId, M.OrderId);
       Assert.AreEqual(Xml, M.Xml);
 }
        public void Create()
        {
            string Id                  = "85f54628-538a-44fc-8605-ae62364f6c71";
            string Type                = "order-state-change-notification";
            string OrderId             = "841171949013218";
            string Xml                 = "<a>blah</a>\n<b>blah</b>";
            NotificationQueueMessage M = new NotificationQueueMessage(Id, Type, OrderId, Xml);

            Assert.AreEqual(Id, M.Id);
            Assert.AreEqual(Type, M.Type);
            Assert.AreEqual(OrderId, M.OrderId);
            Assert.AreEqual(Xml, M.Xml);
        }
Exemple #4
0
        public async Task AddNotificationQueueMessageAsync(NotificationTemplate template, int id, Guid userGuid, string queueName = null)
        {
            // Load Default Queue Name.
            queueName = queueName ?? ConfigurationManager.AppSettings["NotificationQueue"];

            // Create Message.
            var message = new NotificationQueueMessage
            {
                TemplateName    = template,
                Identifier      = id,
                UserGuid        = userGuid,
                TimestampOffset = DateTimeOffset.UtcNow
            };
            var cloudQueueMessage = new CloudQueueMessage(JsonConvert.SerializeObject(message));

            // Add to Queue.
            await AddCloudQueueMessageAsync(queueName, cloudQueueMessage);
        }
        public void ProcessFiles()
        {
            CreateTempDirs();
            WriteFile(INBOX_DIR, FILENAME1, XML, 40);
            WriteFile(INBOX_DIR, FILENAME2, XML, 50);
            WriteFile(INBOX_DIR, FILENAME3, XML, 60);
            FileSystemNotificationQueue Q = new FileSystemNotificationQueue
                                                (INBOX_DIR, INPROCESS_DIR, SUCCESS_DIR, FAILURE_DIR);

            Assert.AreEqual(3, Q.GetLength());
            NotificationQueueMessage M = Q.Receive();

            Assert.AreEqual("charge-amount-notification", M.Type);
            Assert.AreEqual("345475345", M.OrderId);
            Assert.AreEqual("3rcf-f4wtvgw-gwg5", M.Id);
            Assert.AreEqual(2, Q.GetLength());
            Assert.AreEqual(2, Directory.GetFiles(INBOX_DIR).Length);
            Assert.AreEqual(1, Directory.GetFiles(INPROCESS_DIR).Length);
            Assert.AreEqual(GetFullFileName(INPROCESS_DIR, FILENAME3), Directory.GetFiles(INPROCESS_DIR)[0]);
            Assert.AreEqual(0, Directory.GetFiles(SUCCESS_DIR).Length);
            Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length);
            Q.ProcessingSucceeded(M);
            Assert.AreEqual(2, Directory.GetFiles(INBOX_DIR).Length);
            Assert.AreEqual(0, Directory.GetFiles(INPROCESS_DIR).Length);
            Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length);
            Assert.AreEqual(GetFullFileName(SUCCESS_DIR, FILENAME3), Directory.GetFiles(SUCCESS_DIR)[0]);
            Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length);
            M = Q.Receive();
            Assert.AreEqual("order-state-change-notification", M.Type);
            Assert.AreEqual("245629824", M.OrderId);
            Assert.AreEqual("345g-3w4f-6yg4", M.Id);
            Assert.AreEqual(1, Q.GetLength());
            Assert.AreEqual(1, Directory.GetFiles(INBOX_DIR).Length);
            Assert.AreEqual(1, Directory.GetFiles(INPROCESS_DIR).Length);
            Assert.AreEqual(GetFullFileName(INPROCESS_DIR, FILENAME2), Directory.GetFiles(INPROCESS_DIR)[0]);
            Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length);
            Assert.AreEqual(0, Directory.GetFiles(FAILURE_DIR).Length);
            Q.ProcessingFailed(M);
            Assert.AreEqual(1, Directory.GetFiles(INBOX_DIR).Length);
            Assert.AreEqual(0, Directory.GetFiles(INPROCESS_DIR).Length);
            Assert.AreEqual(1, Directory.GetFiles(SUCCESS_DIR).Length);
            Assert.AreEqual(1, Directory.GetFiles(FAILURE_DIR).Length);
            Assert.AreEqual(GetFullFileName(FAILURE_DIR, FILENAME2), Directory.GetFiles(FAILURE_DIR)[0]);
        }
Exemple #6
0
        static void Main(string[] args)
        {
            INotificationQueue Q = new FileSystemNotificationQueue(
                GetPathFromConfigFile("InboxDir"),
                GetPathFromConfigFile("InProcessDir"),
                GetPathFromConfigFile("SuccessDir"),
                GetPathFromConfigFile("FailureDir"));

            while (true)
            {
                Console.WriteLine("\nWaiting for the next notification.");
                NotificationQueueMessage M = Q.Receive();
                Console.WriteLine("Processing {0} for order {1}.", M.Type, M.OrderId);
                try {
                    ProcessNotification(M.Type, M.Xml);
                    Q.ProcessingSucceeded(M);
                }
                catch (Exception e) {
                    Console.WriteLine(e.ToString());
                    Q.ProcessingFailed(M);
                }
                Console.WriteLine("{0} notifications in queue.", Q.GetLength());
            }
        }