Apache.NMS.ActiveMQ.Test.RollbackRedeliveryTest.TestRedeliveryOnSingleConsumer C# (CSharp) Method

TestRedeliveryOnSingleConsumer() private method

private TestRedeliveryOnSingleConsumer ( ) : void
return void
        public void TestRedeliveryOnSingleConsumer()
        {
            connection.Start();

            PopulateDestinationWithInterleavedProducer(nbMessages, destinationName);

            // Consume messages and Rollback transactions
            {
                int received = 0;
                IDictionary rolledback = Hashtable.Synchronized(new Hashtable());
                ISession session = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination destination = session.GetQueue(destinationName);
                IMessageConsumer consumer = session.CreateConsumer(destination);

                while(received < nbMessages)
                {
                    ITextMessage msg = (ITextMessage) consumer.Receive(TimeSpan.FromMilliseconds(6000000));
                    if(msg != null)
                    {
                        if(msg != null && rolledback.Contains(msg.Text))
                        {
                            Interlocked.Increment(ref received);
                            Assert.IsTrue(msg.NMSRedelivered);
                            session.Commit();
                        }
                        else
                        {
                            rolledback.Add(msg.Text, (Boolean) true);
                            session.Rollback();
                        }
                    }
                }
                consumer.Close();
                session.Close();
            }
        }