Exemplo n.º 1
0
        //[Test]
        public virtual void TestDoChangeSentMessage(
            string testDestRef,
            //[Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
            //	AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode,
            //[Values(true, false)]
            bool doClear)
        {
            using (IConnection connection = CreateConnection())
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    IDestination destination = GetClearDestinationByNodeReference(session, testDestRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                    {
                        IMessageProducer producer = session.CreateProducer(destination);
                        ITextMessage     message  = session.CreateTextMessage();

                        string prefix = "ConsumerTest - TestDoChangeSentMessage: ";

                        for (int i = 0; i < COUNT; i++)
                        {
                            message.Properties[VALUE_NAME] = i;
                            message.Text = prefix + Convert.ToString(i);

                            producer.Send(message);

                            if (doClear)
                            {
                                message.ClearBody();
                                message.ClearProperties();
                            }
                        }

                        if (ackMode == AcknowledgementMode.Transactional)
                        {
                            session.Commit();
                        }

                        for (int i = 0; i < COUNT; i++)
                        {
                            ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
                            Assert.AreEqual(msg.Text, prefix + Convert.ToString(i));
                            Assert.AreEqual(msg.Properties.GetInt(VALUE_NAME), i);
                        }

                        if (ackMode == AcknowledgementMode.Transactional)
                        {
                            session.Commit();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestDoChangeSentMessage(
            [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
                    AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode)
        {
            using (IConnection connection = CreateConnection())
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    ITemporaryQueue queue = session.CreateTemporaryQueue();
                    using (IMessageConsumer consumer = session.CreateConsumer(queue))
                    {
                        IMessageProducer producer = session.CreateProducer(queue);
                        ITextMessage     message  = session.CreateTextMessage();

                        string prefix = "ConsumerTest - TestDoChangeSentMessage: ";

                        for (int i = 0; i < COUNT; i++)
                        {
                            message.Properties[VALUE_NAME] = i;
                            message.Text = prefix + Convert.ToString(i);

                            producer.Send(message);

                            message.ClearBody();
                            message.ClearProperties();
                        }

                        if (ackMode == AcknowledgementMode.Transactional)
                        {
                            session.Commit();
                        }

                        for (int i = 0; i < COUNT; i++)
                        {
                            ITextMessage msg = consumer.Receive(TimeSpan.FromMilliseconds(2000)) as ITextMessage;
                            Assert.AreEqual(msg.Text, prefix + Convert.ToString(i));
                            Assert.AreEqual(msg.Properties.GetInt(VALUE_NAME), i);
                        }

                        if (ackMode == AcknowledgementMode.Transactional)
                        {
                            session.Commit();
                        }
                    }
                }
            }
        }