Esempio n. 1
0
        public void GetMessagesInOrder()
        {
            SendMessage("message 1");
            SendMessage("message 2");
            SendMessage("message 3");
            SendMessage("message 4");

            MessageQueue      mq0 = MQUtil.GetQueue(qName);
            MessageEnumerator me0 = mq0.GetMessageEnumerator();

            me0.MoveNext();
            Console.WriteLine("Message0 {0}", me0.Current.Body);
            me0.MoveNext();
            Console.WriteLine("Message0 {0}", me0.Current.Body);
            me0.MoveNext();
            Console.WriteLine("Message0 {0}", me0.Current.Body);
            me0.MoveNext();
            Console.WriteLine("Message0 {0}", me0.Current.Body);

            me0.Dispose();
            mq0.Dispose();

            MessageQueue      mq1 = MQUtil.GetQueue(qName);
            MessageEnumerator me1 = mq1.GetMessageEnumerator();

            me1.MoveNext();
            Console.WriteLine("Message1 {0}", me1.Current.Body);
            me1.MoveNext();
            Console.WriteLine("Message1 {0}", me1.Current.Body);
            me1.MoveNext();
            Console.WriteLine("Message1 {0}", me1.Current.Body);
            me1.MoveNext();
            Console.WriteLine("Message1 {0}", me1.Current.Body);

            Message m1 = me1.Current;

            m1.Formatter = new BinaryMessageFormatter();
            Assert.AreEqual("message 4", (String)m1.Body, "body incorrect");

            mq1.Purge();
            MessageQueue.Delete(qName);
        }
Esempio n. 2
0
        public void RemoveMessageWithTimeout()
        {
            SendMessage("message 1");
            SendMessage("message 2");
            SendMessage("message 3");
            SendMessage("message 4");

            MessageQueue      mq0 = MQUtil.GetQueue(qName);
            MessageEnumerator me0 = mq0.GetMessageEnumerator();

            TimeSpan ts = new TimeSpan(0, 0, 2);

            me0.MoveNext(ts);
            me0.MoveNext(ts);
            me0.MoveNext(ts);

            Message m0 = me0.RemoveCurrent(ts);

            me0.MoveNext(ts);

            me0.Dispose();
            mq0.Dispose();

            MessageQueue      mq1 = MQUtil.GetQueue(qName);
            MessageEnumerator me1 = mq1.GetMessageEnumerator();

            me1.MoveNext(ts);
            me1.MoveNext(ts);
            me1.MoveNext(ts);

            Message m1 = me1.Current;

            m1.Formatter = new BinaryMessageFormatter();
            Assert.AreEqual("message 4", (String)m1.Body, "body incorrect");

            mq1.Purge();
            MessageQueue.Delete(qName);
        }