public void TestRedeliveryOnSingleSession()
{
connection.Start();
PopulateDestination(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);
while(received < nbMessages)
{
IMessageConsumer consumer = session.CreateConsumer(destination);
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();
}
}