Esempio n. 1
0
 private void InsertToGraveyard(MongoDeadLetterGraveyardDocument graveyardDoc)
 {
     try
     {
         _deadLetterGraveyard.InsertOne(graveyardDoc);
     }
     catch (Exception e)
     {
         throw new ApplicationException("Exception inserting document into graveyard", e);
     }
 }
Esempio n. 2
0
        public void SendToGraveyard(BasicDeliverEventArgs deliverArgs, IMessageHeader header, string reason, Exception cause = null)
        {
            _logger.Debug("Sending message " + header.MessageGuid + " to the graveyard (" + reason + ")");

            var graveyardDoc = new MongoDeadLetterGraveyardDocument(deliverArgs, header.MessageGuid, reason, cause);

            lock (_oDbLock)
            {
                InsertToGraveyard(graveyardDoc);
            }
        }
Esempio n. 3
0
        public void TestMessageRejectLoop()
        {
            Assert.True(_deadLetterCollection.CountDocuments(FilterDefinition <MongoDeadLetterDocument> .Empty) == 0);
            Assert.True(_deadLetterGraveyard.CountDocuments(FilterDefinition <MongoDeadLetterGraveyardDocument> .Empty) == 0);

            // Setup a test message and send it, then wait for it to be rejected
            var testMessage = new AccessionDirectoryMessage
            {
                NationalPACSAccessionNumber = "1234",
                DirectoryPath = TestContext.CurrentContext.TestDirectory
            };

            // Set so the host just pushes the message through each time
            _cliOptions.FlushMessages = true;

            // Send the message
            IMessageHeader originalHeader = _testHelper.TestProducer.SendMessage(testMessage, null, DeadLetterTestHelper.TestRoutingKey);

            for (var i = 0; i < _testHelper.GlobalOptions.DeadLetterReprocessorOptions.MaxRetryLimit + 1; i++)
            {
                Assert.True(_deadLetterGraveyard.CountDocuments(FilterDefinition <MongoDeadLetterGraveyardDocument> .Empty) == 0);

                int count = i + 1;
                new TestTimelineAwaiter().Await(() => _testHelper.MessageRejectorConsumer.NackCount == count);

                // Check 1 message on the DLQ
                Assert.AreEqual(1, _testHelper.TestModel.MessageCount(DeadLetterTestHelper.TestDlQueueName));

                // Start the host and check message has been read from DLQ into store
                var host = new DeadLetterReprocessorHost(_testHelper.GlobalOptions, _cliOptions);
                host.Start();

                Assert.True(_deadLetterCollection.CountDocuments(FilterDefinition <MongoDeadLetterDocument> .Empty) == 0);
            }

            // Message should now be in the graveyard
            Assert.True(_deadLetterGraveyard.CountDocuments(FilterDefinition <MongoDeadLetterGraveyardDocument> .Empty) == 1);

            MongoDeadLetterGraveyardDocument graveyardDoc = _deadLetterGraveyard.Find(FilterDefinition <MongoDeadLetterGraveyardDocument> .Empty).Single();

            Assert.AreEqual(graveyardDoc.MessageGuid, graveyardDoc.DeadLetter.MessageGuid);
            Assert.AreEqual(originalHeader.MessageGuid, graveyardDoc.DeadLetter.Props.MessageHeader.Parents[0]);
            Assert.AreEqual("MaxRetryCount exceeded", graveyardDoc.Reason);
            Assert.True((DateTime.UtcNow - graveyardDoc.KilledAt) < TimeSpan.FromSeconds(5));
        }