/// <summary>
 /// Initializes a new instance of the <see cref="CachedMessageProducer"/> class.
 /// </summary>
 /// <param name="target">The target.</param>
 public CachedMessageProducer(IMessageProducer target)
 {
     this.target = target;
     this.msgDeliveryMode = target.DeliveryMode;
     this.priority = target.Priority;
     this.timeToLive = target.TimeToLive;
 }
Example #2
0
        public Queue(MsgDeliveryMode mode = MsgDeliveryMode.NonPersistent)
        {
            Uri msgQueue = new Uri("activemq:tcp://localhost:61616");

            _factory = new ConnectionFactory(msgQueue);
            try
            {
                _connection = _factory.CreateConnection();
            }
            catch (NMSConnectionException ex)
            {
                Log.FatalException("Error connecting to MQ server", ex);
                throw;
            }
            // TODO check _connection for null
            _connection.RequestTimeout = TimeSpan.FromSeconds(60);
            Session = _connection.CreateSession();

            // TODO need to find out if queue exists.
            // It creates a new queue if it doesn't exist.
            _destination = Session.GetDestination("queue://TwitterSearchStream");
            _consumer = Session.CreateConsumer(_destination);

            _producer = Session.CreateProducer(_destination);
            _producer.RequestTimeout = TimeSpan.FromSeconds(60);
            _producer.DeliveryMode = mode;

            _connection.Start();

            _connection.ExceptionListener += _connection_ExceptionListener;
            _connection.ConnectionInterruptedListener += _connection_ConnectionInterruptedListener;
        }
Example #3
0
        public PooledProducer(IMessageProducer producer, IDestination destination)
        {
            this.producer = producer;
            this.destination = destination;

            this.deliveryMode = producer.DeliveryMode;
            this.disableMessageID = producer.DisableMessageID;
            this.disableMessageTimestamp = producer.DisableMessageTimestamp;
            this.priority = producer.Priority;
            this.timeToLive = producer.TimeToLive;
        }
Example #4
0
        public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            if (destination == null)
            {
                destination = this.destination;
            }

            IMessageProducer producer = this.MessageProducer;

            lock(producer)
            {
                producer.Send(destination, message, deliveryMode, priority, timeToLive);
            }
        }
        public virtual void SetUp()
        {
            this.nmsMessageID = "testid";
            this.nmsCorrelationID = "testcorrelationid";
            this.nmsDestination = new ActiveMQTopic("test.topic");
            this.nmsReplyTo = new ActiveMQTempTopic("test.replyto.topic:001");
            this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent;
            this.nmsRedelivered = true;
            this.nmsType = "test type";
            this.nmsPriority = MsgPriority.High;
            this.nmsTimestamp = DateTime.Now;
            this.consumerIDs = new long[3];

            for(int i = 0; i < this.consumerIDs.Length; i++)
            {
                this.consumerIDs[i] = i;
            }
        }
Example #6
0
        public void TestRedispatchOfUncommittedTx(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                ISession     session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination destination = CreateDestination(session, DestinationType.Queue);

                SendMessages(connection, destination, deliveryMode, 2);

                IMessageConsumer consumer = session.CreateConsumer(destination);
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(2000)));
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(2000)));

                // install another consumer while message dispatch is unacked/uncommitted
                ISession         redispatchSession  = connection.CreateSession(AcknowledgementMode.Transactional);
                IMessageConsumer redispatchConsumer = redispatchSession.CreateConsumer(destination);

                // no commit so will auto rollback and get re-dispatched to redisptachConsumer
                session.Close();

                IMessage msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(2000));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));

                msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(2000));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
                redispatchSession.Commit();

                Assert.IsNull(redispatchConsumer.Receive(TimeSpan.FromMilliseconds(500)));
                redispatchSession.Close();
            }
        }
Example #7
0
        public void SendReceiveBytesMessageContentTest(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IBytesMessage request = session.CreateBytesMessage();

                            request.WriteBoolean(true);
                            request.WriteByte((byte)1);
                            request.WriteBytes(new byte[1]);
                            request.WriteBytes(new byte[3], 0, 2);
                            request.WriteChar('a');
                            request.WriteDouble(1.5);
                            request.WriteSingle((float)1.5);
                            request.WriteInt32(1);
                            request.WriteInt64(1);
                            request.WriteObject("stringobj");
                            request.WriteInt16((short)1);
                            request.WriteString("utfstring");

                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertBytesMessageEqual(request, message);
                            AssertMessageIsReadOnly(message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Sends the message to the given destination with the explicit QoS
        /// configuration.
        /// </summary>
        public void Send(Apache.NMS.IDestination destination,
                         Apache.NMS.IMessage message, MsgDeliveryMode deliveryMode,
                         MsgPriority priority, TimeSpan timeToLive)
        {
            Apache.NMS.XMS.Destination dest =
                (Apache.NMS.XMS.Destination)destination;

            Apache.NMS.XMS.Message msg = GetXMSMessage(message);

            try
            {
                this.xmsMessageProducer.Send(
                    dest.xmsDestination,
                    msg.xmsMessage,
                    XMSConvert.ToJMSDeliveryMode(deliveryMode),
                    (int)priority,
                    (long)timeToLive.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                ExceptionUtil.WrapAndThrowNMSException(ex);
            }
        }
        //[Test]
        public virtual void TestStartAfterSend(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode,
            //[Values(DestinationType.Queue, DestinationType.Topic)]
            DestinationType destinationType, string testDestinationRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                ISession         session     = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
                IDestination     destination = GetClearDestination(session, destinationType, testDestinationRef);
                IMessageConsumer consumer    = session.CreateConsumer(destination);

                // Send the messages
                SendMessages(session, destination, deliveryMode, 1);

                // Start the conncection after the message was sent.
                connection.Start();

                // Make sure only 1 message was delivered.
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1000)));
                Assert.IsNull(consumer.ReceiveNoWait());
            }
        }
Example #10
0
        public void SendReceiveBytesMessage(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IMessage request = session.CreateBytesMessage(msgContent);
                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertBytesMessageEqual(request, message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
        public void TestCreateConsumerBeforeSendAddListenerAfterSend(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnectionAndStart(GetTestClientId()))
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                    using (IDestination destination = CreateDestination(session, DestinationType.Queue))
                        using (IMessageConsumer consumer = session.CreateConsumer(destination))
                            using (IMessageProducer producer = session.CreateProducer(destination))
                            {
                                producer.DeliveryMode = deliveryMode;

                                IMessage request = session.CreateMessage();
                                request.NMSCorrelationID = "AsyncConsumeAfterSendLateListener";
                                request.NMSType          = "Test";
                                producer.Send(request);

                                // now lets add the listener
                                consumer.Listener += new MessageListener(OnMessage);
                                WaitForMessageToArrive();
                                Assert.AreEqual(request.NMSCorrelationID, receivedMsg.NMSCorrelationID, "Invalid correlation ID.");
                            }
        }
Example #12
0
        public void TestReceiveRollbackNonTransaction(AcknowledgementMode ackMode, MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(ackMode))
                {
                    IDestination destination = session.CreateTemporaryQueue();
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            ITextMessage firstMsgSend = session.CreateTextMessage("ReceiveCommitNonTransaction Message");
                            producer.Send(firstMsgSend);

                            // Receive the messages

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertTextMessageEqual(firstMsgSend, message, "First message does not match.");
                            if (AcknowledgementMode.ClientAcknowledge == ackMode)
                            {
                                message.Acknowledge();
                            }

                            try
                            {
                                session.Rollback();
                                Assert.Fail("Should have thrown an InvalidOperationException.");
                            }
                            catch (InvalidOperationException)
                            {
                            }
                        }
                }
            }
        }
Example #13
0
        //[Test]
        public virtual void TestRedispatchOfRolledbackTx(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testDestRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                ISession     session     = connection.CreateSession(AcknowledgementMode.Transactional);
                IDestination destination = GetClearDestinationByNodeReference(session, testDestRef);

                SendMessages(connection, destination, deliveryMode, 2);

                IMessageConsumer consumer = session.CreateConsumer(destination);
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1500)));
                Assert.IsNotNull(consumer.Receive(TimeSpan.FromMilliseconds(1500)));

                // install another consumer while message dispatch is unacked/uncommitted
                ISession         redispatchSession  = connection.CreateSession(AcknowledgementMode.Transactional);
                IMessageConsumer redispatchConsumer = redispatchSession.CreateConsumer(destination);

                session.Rollback();
                session.Close();

                IMessage msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1500));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
                msg = redispatchConsumer.Receive(TimeSpan.FromMilliseconds(1500));
                Assert.IsNotNull(msg);
                Assert.IsTrue(msg.NMSRedelivered);
                Assert.AreEqual(2, msg.Properties.GetLong("NMSXDeliveryCount"));
                redispatchSession.Commit();

                Assert.IsNull(redispatchConsumer.Receive(TimeSpan.FromMilliseconds(500)));
                redispatchSession.Close();
            }
        }
Example #14
0
        public void SendReceiveTextMessage(
            [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IMessage request = session.CreateTextMessage("Hello World!");
                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertTextMessageEqual(request, message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
Example #15
0
        //[Test]
        public virtual void TestSendReceiveTextMessage(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testQueueRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IMessage request = session.CreateTextMessage("Hello World!");
                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertTextMessageEqual(request, message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
Example #16
0
        public void SendReceiveBytesMessage(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = session.CreateTemporaryTopic();
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IMessage request = session.CreateBytesMessage(msgContent);
                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            AssertBytesMessageEqual(request, message);
                            AssertMessageIsReadOnly(message);
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                        }
                }
            }
        }
Example #17
0
        public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            try
            {
                if (this.ProducerTransformer != null)
                {
                    IMessage transformed = this.ProducerTransformer(this.session, this, message);
                    if (transformed != null)
                    {
                        message = transformed;
                    }
                }

                message.NMSDeliveryMode = deliveryMode;
                message.NMSTimeToLive   = timeToLive;
                message.NMSPriority     = priority;
                if (!DisableMessageTimestamp)
                {
                    message.NMSTimestamp = DateTime.UtcNow;
                }

                if (!DisableMessageID)
                {
                    // TODO: message.NMSMessageId =
                }

                // Convert the Message into a Amqp message
                Message msg = session.MessageConverter.ToAmqpMessage(message);

                qpidSender.Send(msg);
            }
            catch (Exception e)
            {
                throw new NMSException(e.Message + ": " /* TODO: + dest */, e);
            }
        }
Example #18
0
        private void Setup(INmsConnection connection, MsgDeliveryMode deliveryMode, bool synchronous)
        {
            this.isSynchronous = synchronous;
            this.deliveryMode = deliveryMode;
            this.connection = connection;
            this.session = connection.GetSession();
            this.messageFactory = new MessageFactory(this.session.InnerSession);
            this.connection.ConnectionInterrupted += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionInterrupted);
            this.connection.ConnectionResumed += new EventHandler<NmsConnectionEventArgs>(connection_ConnectionResumed);

            if (this.innerDestination == null)
            {
                this.producer = this.session.CreateProducer();
            }
            else
            {
                this.destination = this.innerDestination.GetDestination(this.session);
                this.producer = this.session.CreateProducer(this.destination);
            }

            this.producer.DeliveryMode = deliveryMode;

            if (synchronous)
                this.InitializeForSynchronous();

            this.isInitialized = true;
            this.asr.Set();
        }
Example #19
0
 public void SendMessages(ISession session, IDestination destination, MsgDeliveryMode deliveryMode, int count)
 {
     IMessageProducer producer = session.CreateProducer(destination);
     producer.DeliveryMode = deliveryMode;
     for(int i = 0; i < count; i++)
     {
         producer.Send(session.CreateTextMessage("" + i));
     }
     producer.Close();
 }
Example #20
0
        //[Test]
        public virtual void TestSendReceiveNestedMapMessage(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testQueueRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            try
                            {
                                producer.DeliveryMode = deliveryMode;
                                IMapMessage  request        = session.CreateMapMessage();
                                const string textFieldValue = "Nested Map Messages Rule!";

                                request.Body.SetString("textField", textFieldValue);

                                IDictionary grandChildMap = new Hashtable();
                                grandChildMap["x"] = "abc";
                                grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });

                                IDictionary nestedMap = new Hashtable();
                                nestedMap["a"] = "foo";
                                nestedMap["b"] = (int)23;
                                nestedMap["c"] = (long)45;
                                nestedMap["d"] = grandChildMap;

                                request.Body.SetDictionary("mapField", nestedMap);
                                request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));

                                producer.Send(request);

                                IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
                                Assert.IsNotNull(message, "No message returned!");
                                Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
                                Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                                string textFieldResponse = message.Body.GetString("textField");
                                Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");

                                IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
                                Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
                                Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
                                Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
                                Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
                                Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");

                                IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
                                Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
                                Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
                                Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");

                                IList grandChildList = grandChildMapResponse["y"] as IList;
                                Assert.IsNotNull(grandChildList, "Grand child list not returned.");
                                Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
                                Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
                                Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
                                Assert.AreEqual("c", grandChildList[2], "grandChildList: c");

                                IList listFieldResponse = message.Body.GetList("listField");
                                Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
                                Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
                                Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
                                Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
                                Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
                            }
                            catch (NotSupportedException)
                            {
                            }
                            catch (NMSException e)
                            {
                                Assert.IsTrue(e.InnerException.GetType() == typeof(NotSupportedException));
                            }
                        }
                }
            }
        }
 public void TestAsynchronousTextMessageConsume(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestAsynchronousTextMessageConsume(deliveryMode, DEFAULT_TEST_QUEUE);
 }
        public void TestReceiveIgnoreExpirationMessage(
            [Values(AcknowledgementMode.AutoAcknowledge, AcknowledgementMode.ClientAcknowledge,
                    AcknowledgementMode.DupsOkAcknowledge, AcknowledgementMode.Transactional)]
            AcknowledgementMode ackMode,
            [Values(MsgDeliveryMode.NonPersistent, MsgDeliveryMode.Persistent)]
            MsgDeliveryMode deliveryMode,
            [Values(ExpirationOptions.DEFAULT, ExpirationOptions.IGNORE, ExpirationOptions.DO_NOT_IGNORE)]
            ExpirationOptions expirationOption)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (Session session = connection.CreateSession(ackMode) as Session)
                {
                    string destinationName = DESTINATION_NAME;

                    if (ExpirationOptions.IGNORE == expirationOption)
                    {
                        destinationName += "?consumer.nms.ignoreExpiration=true";
                    }
                    else if (ExpirationOptions.DO_NOT_IGNORE == expirationOption)
                    {
                        destinationName += "?consumer.nms.ignoreExpiration=false";
                    }

                    try
                    {
                        IDestination destination = SessionUtil.GetDestination(session, destinationName);

                        using (IMessageConsumer consumer = session.CreateConsumer(destination))
                            using (IMessageProducer producer = session.CreateProducer(destination))
                            {
                                producer.DeliveryMode = deliveryMode;

                                string msgText = string.Format("ExpiredMessage: {0}", Guid.NewGuid().ToString());

                                TextMessage msg = session.CreateTextMessage(msgText) as TextMessage;

                                // Give it two seconds to live.
                                msg.NMSTimeToLive = TimeSpan.FromMilliseconds(2000);

                                producer.Send(msg);

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

                                // Wait for four seconds before processing it.  The broker will have sent it to our local
                                // client dispatch queue, but we won't attempt to process the message until it has had
                                // a chance to expire within our internal queue system.
                                Thread.Sleep(4000);

                                TextMessage rcvMsg = consumer.ReceiveNoWait() as TextMessage;

                                if (ExpirationOptions.IGNORE == expirationOption)
                                {
                                    Assert.IsNotNull(rcvMsg, "Did not receive expired message.");
                                    rcvMsg.Acknowledge();

                                    Assert.AreEqual(msgText, rcvMsg.Text, "Message text does not match.");
                                    Assert.IsTrue(rcvMsg.IsExpired());

                                    if (AcknowledgementMode.Transactional == ackMode)
                                    {
                                        session.Commit();
                                    }
                                }
                                else
                                {
                                    // Should not receive a message.
                                    Assert.IsNull(rcvMsg, "Received an expired message!");
                                }

                                consumer.Close();
                                producer.Close();
                            }
                    }
                    finally
                    {
                        try
                        {
                            // Ensure that Session resources on the Broker release transacted Consumers.
                            session.Close();
                            // Give the Broker some time to remove the subscriptions.
                            Thread.Sleep(2000);
                            SessionUtil.DeleteDestination(session, destinationName);
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
Example #23
0
 public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     Send(destination, message, deliveryMode, priority, timeToLive);
 }
		/// <summary>
		/// Sends the message to the given destination with the explicit QoS configuration.  The object must be serializable to XML.
		/// </summary>
		public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
		{
			producer.Send(destination, producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive);
		}
Example #25
0
 NmsProducer INmsConnection.CreateProducer(Destination destination, MsgDeliveryMode messageDeliveryMode)
 {
     return new NmsProducer(this, destination, messageDeliveryMode);
 }
Example #26
0
 public NmsProducer CreateSynchronousProducer(Destination destination, MsgDeliveryMode messageDeliveryMode)
 {
     return new NmsProducer(this, destination, deliveryMode: messageDeliveryMode, synchronous: true);
 }
Example #27
0
 public NmsProducer CreateProducer(Destination destination, MsgDeliveryMode messageDeliveryMode)
 {
     return new NmsProducer(this, destination, deliveryMode: messageDeliveryMode);
 }
Example #28
0
 public NmsProducer CreateProducer(Destination destination, MsgDeliveryMode messageDeliveryMode = MsgDeliveryMode.Persistent, bool synchronous = false)
 {
     return new NmsProducer(this, destination, messageDeliveryMode, synchronous);
 }
 /// <summary>
 /// Sends a message to the specified message.
 /// </summary>
 /// <param name="message">The message to send.</param>
 /// <param name="deliveryMode">The QOS to use for sending <see cref="msgDeliveryMode"/>.</param>
 /// <param name="priority">The message priority.</param>
 /// <param name="timeToLive">The time to live.</param>
 public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
    target.Send(message, deliveryMode, priority, timeToLive);
 }
Example #30
0
 public void SendMessages(IDestination destination, MsgDeliveryMode deliveryMode, int count)
 {
     IConnection connection = CreateConnection();
     connection.Start();
     SendMessages(connection, destination, deliveryMode, count);
     connection.Close();
 }
Example #31
0
        public void SendRequest(Destination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority messagePriority, TimeSpan timeToLive)
        {
            if (!this.isInitialized)
                this.asr.WaitOne(10000);

            this.producer.Send(destination.GetDestination(this.session), message, deliveryMode, messagePriority, timeToLive);
        }
Example #32
0
        public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
        {
            try
            {
                if (this.ProducerTransformer != null)
                {
                    IMessage transformed = this.ProducerTransformer(this.session, this, message);
                    if (transformed != null)
                    {
                        message = transformed;
                    }
                }

                message.NMSDeliveryMode = deliveryMode;
                message.NMSTimeToLive = timeToLive;
                message.NMSPriority = priority;
                if (!DisableMessageTimestamp)
                {
                    message.NMSTimestamp = DateTime.UtcNow;
                }

                if (!DisableMessageID)
                {
                    // TODO: message.NMSMessageId =
                }

                // Convert the Message into a Amqp message
                Message msg = session.MessageConverter.ToAmqpMessage(message);

                qpidSender.Send(msg);
            }
            catch (Exception e)
            {
                throw new NMSException(e.Message + ": " /* TODO: + dest */, e);
            }
        }
Example #33
0
 NmsProducer INmsConnection.CreateSynchronousProducer(Destination destination, MsgDeliveryMode messageDeliveryMode)
 {
     return this.GetConnection().CreateProducer(destination, messageDeliveryMode: messageDeliveryMode, synchronous: true);
 }
Example #34
0
 public void SendRequest(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority messagePriority, TimeSpan timeToLive)
 {
     this.producer.Send(message, deliveryMode, messagePriority, timeToLive);
 }
Example #35
0
        //[Test]
        public virtual void TestSendSessionClose(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testQueueRef)
        {
            ITextMessage firstMsgSend;
            ITextMessage secondMsgSend;

            using (IConnection connection1 = CreateConnection(GetTestClientId()))
            {
                connection1.Start();
                using (ISession session1 = connection1.CreateSession(AcknowledgementMode.Transactional))
                {
                    IDestination destination1 = GetClearDestination(session1, DestinationType.Queue, testQueueRef);
                    using (IMessageConsumer consumer = session1.CreateConsumer(destination1))
                    {
                        // First connection session that sends one message, and the
                        // second message is implicitly rolled back as the session is
                        // disposed before Commit() can be called.
                        using (IConnection connection2 = CreateConnection(GetTestClientId()))
                        {
                            connection2.Start();
                            using (ISession session2 = connection2.CreateSession(AcknowledgementMode.Transactional))
                            {
                                IDestination destination2 = GetClearDestination(session2, DestinationType.Queue, testQueueRef);
                                using (IMessageProducer producer = session2.CreateProducer(destination2))
                                {
                                    producer.DeliveryMode = deliveryMode;
                                    firstMsgSend          = session2.CreateTextMessage("First Message");
                                    producer.Send(firstMsgSend);
                                    session2.Commit();

                                    ITextMessage rollbackMsg = session2.CreateTextMessage("I'm going to get rolled back.");
                                    producer.Send(rollbackMsg);
                                }
                            }
                        }

                        // Second connection session that will send one message.
                        using (IConnection connection2 = CreateConnection(GetTestClientId()))
                        {
                            connection2.Start();
                            using (ISession session2 = connection2.CreateSession(AcknowledgementMode.Transactional))
                            {
                                IDestination destination2 = GetClearDestination(session2, DestinationType.Queue, testQueueRef);
                                using (IMessageProducer producer = session2.CreateProducer(destination2))
                                {
                                    producer.DeliveryMode = deliveryMode;
                                    secondMsgSend         = session2.CreateTextMessage("Second Message");
                                    producer.Send(secondMsgSend);
                                    session2.Commit();
                                }
                            }
                        }

                        // Check the consumer to verify which messages were actually received.
                        IMessage message = consumer.Receive(receiveTimeout);
                        AssertTextMessageEqual(firstMsgSend, message, "First message does not match.");

                        message = consumer.Receive(receiveTimeout);
                        AssertTextMessageEqual(secondMsgSend, message, "Second message does not match.");

                        // validates that the rollback was not consumed
                        session1.Commit();
                    }
                }
            }
        }
Example #36
0
        protected void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive, bool specifiedTimeToLive)
        {
            if(null == destination)
            {
                // See if this producer was created without a destination.
                if(null == info.Destination)
                {
                    throw new NotSupportedException();
                }

                // The producer was created with a destination, but an invalid destination
                // was specified.
                throw new Apache.NMS.InvalidDestinationException();
            }

            ActiveMQDestination dest = null;

            if(destination == this.info.Destination)
            {
                dest = destination as ActiveMQDestination;
            }
            else if(info.Destination == null)
            {
                dest = ActiveMQDestination.Transform(destination);
            }
            else
            {
                throw new NotSupportedException("This producer can only send messages to: " + this.info.Destination.PhysicalName);
            }

            if(this.ProducerTransformer != null)
            {
                IMessage transformed = this.ProducerTransformer(this.session, this, message);
                if(transformed != null)
                {
                    message = transformed;
                }
            }

            ActiveMQMessage activeMessage = this.messageTransformation.TransformMessage<ActiveMQMessage>(message);

            activeMessage.ProducerId = info.ProducerId;
            activeMessage.Destination = dest;
            activeMessage.NMSDeliveryMode = deliveryMode;
            activeMessage.NMSPriority = priority;

            // Always set the message Id regardless of the disable flag.
            MessageId id = new MessageId();
            id.ProducerId = info.ProducerId;
            id.ProducerSequenceId = Interlocked.Increment(ref this.producerSequenceId);
            activeMessage.MessageId = id;

            if(!disableMessageTimestamp)
            {
                activeMessage.NMSTimestamp = DateTime.UtcNow;
            }

            if(specifiedTimeToLive)
            {
                activeMessage.NMSTimeToLive = timeToLive;
            }

            // Ensure there's room left to send this message
            if(this.usage != null)
            {
                usage.WaitForSpace();
            }

            lock(closedLock)
            {
                if(closed)
                {
                    throw new ConnectionClosedException();
                }

                session.DoSend(activeMessage, this, this.usage, this.RequestTimeout);
            }
        }
 public void TestSendSessionClose(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestSendSessionClose(deliveryMode, TRANSACTION_TEST_QUEUE);
 }
 public void TestCreateConsumerBeforeSendAddListenerAfterSend(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestCreateConsumerBeforeSendAddListenerAfterSend(deliveryMode, DEFAULT_TEST_QUEUE);
 }
 public void TestRedispatchOfRolledbackTx(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestRedispatchOfRolledbackTx(deliveryMode, TRANSACTION_TEST_QUEUE);
 }
        //[Test]
        public virtual void TestSendReceiveStreamMessage(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testDestRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestinationByNodeReference(session, testDestRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IStreamMessage request;

                            try
                            {
                                request = session.CreateStreamMessage();
                            }
                            catch (System.NotSupportedException)
                            {
                                return;
                            }

                            request.WriteBoolean(a);
                            request.WriteByte(b);
                            request.WriteChar(c);
                            request.WriteInt16(d);
                            request.WriteInt32(e);
                            request.WriteInt64(f);
                            request.WriteString(g);
                            request.WriteBoolean(h);
                            request.WriteByte(i);
                            request.WriteInt16(j);
                            request.WriteInt32(k);
                            request.WriteInt64(l);
                            request.WriteSingle(m);
                            request.WriteDouble(n);
                            producer.Send(request);

                            IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                            // use generic API to access entries
                            Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a");
                            Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b");
                            Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c");
                            Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d");
                            Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e");
                            Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f");
                            Assert.AreEqual(g, message.ReadString(), "Stream String Value: g");
                            Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h");
                            Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i");
                            Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j");
                            Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k");
                            Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l");
                            Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m");
                            Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n");
                        }
                }
            }
        }
Example #41
0
 /// <summary>
 /// Sends the message to the given destination with the explicit QoS configuration.  The object must be serializable to XML.
 /// </summary>
 public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     producer.Send(destination, producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive);
 }
Example #42
0
        //[Test]
        public virtual void TestSendReceiveMapMessage(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testQueueRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IMapMessage request = session.CreateMapMessage();
                            request.Body["a"] = a;
                            request.Body["b"] = b;
                            request.Body["c"] = c;
                            request.Body["d"] = d;
                            request.Body["e"] = e;
                            request.Body["f"] = f;
                            request.Body["g"] = g;
                            request.Body["h"] = h;
                            request.Body["i"] = i;
                            request.Body["j"] = j;
                            request.Body["k"] = k;
                            request.Body["l"] = l;
                            request.Body["m"] = m;
                            request.Body["n"] = n;
                            request.Body["o"] = o;
                            producer.Send(request);

                            IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                            Assert.AreEqual(ToHex(f), ToHex(message.Body.GetLong("f")), "map entry: f as hex");

                            // use generic API to access entries
                            Assert.AreEqual(a, message.Body["a"], "generic map entry: a");
                            Assert.AreEqual(b, message.Body["b"], "generic map entry: b");
                            Assert.AreEqual(c, message.Body["c"], "generic map entry: c");
                            Assert.AreEqual(d, message.Body["d"], "generic map entry: d");
                            Assert.AreEqual(e, message.Body["e"], "generic map entry: e");
                            Assert.AreEqual(f, message.Body["f"], "generic map entry: f");
                            Assert.AreEqual(g, message.Body["g"], "generic map entry: g");
                            Assert.AreEqual(h, message.Body["h"], "generic map entry: h");
                            Assert.AreEqual(i, message.Body["i"], "generic map entry: i");
                            Assert.AreEqual(j, message.Body["j"], "generic map entry: j");
                            Assert.AreEqual(k, message.Body["k"], "generic map entry: k");
                            Assert.AreEqual(l, message.Body["l"], "generic map entry: l");
                            Assert.AreEqual(m, message.Body["m"], "generic map entry: m");
                            Assert.AreEqual(n, message.Body["n"], "generic map entry: n");
                            Assert.AreEqual(o, message.Body["o"], "generic map entry: o");

                            // use type safe APIs
                            Assert.AreEqual(a, message.Body.GetBool("a"), "map entry: a");
                            Assert.AreEqual(b, message.Body.GetByte("b"), "map entry: b");
                            Assert.AreEqual(c, message.Body.GetChar("c"), "map entry: c");
                            Assert.AreEqual(d, message.Body.GetShort("d"), "map entry: d");
                            Assert.AreEqual(e, message.Body.GetInt("e"), "map entry: e");
                            Assert.AreEqual(f, message.Body.GetLong("f"), "map entry: f");
                            Assert.AreEqual(g, message.Body.GetString("g"), "map entry: g");
                            Assert.AreEqual(h, message.Body.GetBool("h"), "map entry: h");
                            Assert.AreEqual(i, message.Body.GetByte("i"), "map entry: i");
                            Assert.AreEqual(j, message.Body.GetShort("j"), "map entry: j");
                            Assert.AreEqual(k, message.Body.GetInt("k"), "map entry: k");
                            Assert.AreEqual(l, message.Body.GetLong("l"), "map entry: l");
                            Assert.AreEqual(m, message.Body.GetFloat("m"), "map entry: m");
                            Assert.AreEqual(n, message.Body.GetDouble("n"), "map entry: n");
                            Assert.AreEqual(o, message.Body.GetBytes("o"), "map entry: o");
                        }
                }
            }
        }
Example #43
0
 public void SendMessages(IConnection connection, IDestination destination, MsgDeliveryMode deliveryMode, int count)
 {
     ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge);
     SendMessages(session, destination, deliveryMode, count);
     session.Close();
 }
Example #44
0
 public void Send(IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     Send(Destination, message, deliveryMode, priority, timeToLive);
 }
        public void TestCopy()
        {
            this.nmsMessageID = "ID:1141:45278:429";
            this.nmsCorrelationID = "testcorrelationid";
            this.nmsDestination = new ActiveMQTopic("test.topic");
            this.nmsReplyTo = new ActiveMQTempTopic("test.replyto.topic:001");
            this.nmsDeliveryMode = MsgDeliveryMode.NonPersistent;
            this.nmsType = "test type";
            this.nmsPriority = MsgPriority.High;
            this.nmsTimestamp = DateTime.Now;

            ActiveMQMessage msg1 = new ActiveMQMessage();
            msg1.NMSMessageId = this.nmsMessageID;
            msg1.NMSCorrelationID = this.nmsCorrelationID;
            msg1.FromDestination = this.nmsDestination;
            msg1.NMSReplyTo = this.nmsReplyTo;
            msg1.NMSDeliveryMode = this.nmsDeliveryMode;
            msg1.NMSType = this.nmsType;
            msg1.NMSPriority = this.nmsPriority;
            msg1.NMSTimestamp = this.nmsTimestamp;
            msg1.ReadOnlyProperties = true;

            ActiveMQMessage msg2 = msg1.Clone() as ActiveMQMessage;

            Assert.IsTrue(msg1.NMSMessageId.Equals(msg2.NMSMessageId));
            Assert.IsTrue(msg1.NMSCorrelationID.Equals(msg2.NMSCorrelationID));
            Assert.IsTrue(msg1.NMSDestination.Equals(msg2.NMSDestination));
            Assert.IsTrue(msg1.NMSReplyTo.Equals(msg2.NMSReplyTo));
            Assert.IsTrue(msg1.NMSDeliveryMode == msg2.NMSDeliveryMode);
            Assert.IsTrue(msg1.NMSRedelivered == msg2.NMSRedelivered);
            Assert.IsTrue(msg1.NMSType.Equals(msg2.NMSType));
            Assert.IsTrue(msg1.NMSPriority == msg2.NMSPriority);
            Assert.IsTrue(msg1.NMSTimestamp == msg2.NMSTimestamp);
        }
 public void TestReceiveTwoThenRollback(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestReceiveTwoThenRollback(deliveryMode, TRANSACTION_TEST_QUEUE);
 }
 public void TestSendReceiveNMSProperties(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestSendReceiveNMSProperties(deliveryMode, DEFAULT_TEST_QUEUE);
 }
Example #48
0
        public void SendReceiveNestedMapMessage(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IMapMessage  request        = session.CreateMapMessage();
                            const string textFieldValue = "Nested Map Messages Rule!";

                            request.Body.SetString("textField", textFieldValue);

                            IDictionary grandChildMap = new Hashtable();
                            grandChildMap["x"] = "abc";
                            grandChildMap["y"] = new ArrayList(new object[] { "a", "b", "c" });

                            IDictionary nestedMap = new Hashtable();
                            nestedMap["a"] = "foo";
                            nestedMap["b"] = (int)23;
                            nestedMap["c"] = (long)45;
                            nestedMap["d"] = grandChildMap;

                            request.Body.SetDictionary("mapField", nestedMap);
                            request.Body.SetList("listField", new ArrayList(new Object[] { "a", "b", "c" }));

                            producer.Send(request);

                            IMapMessage message = consumer.Receive(receiveTimeout) as IMapMessage;
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(request.Body.Count, message.Body.Count, "Invalid number of message maps.");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");

                            string textFieldResponse = message.Body.GetString("textField");
                            Assert.AreEqual(textFieldValue, textFieldResponse, "textField does not match.");

                            IDictionary nestedMapResponse = message.Body.GetDictionary("mapField");
                            Assert.IsNotNull(nestedMapResponse, "Nested map not returned.");
                            Assert.AreEqual(nestedMap.Count, nestedMapResponse.Count, "nestedMap: Wrong number of elements");
                            Assert.AreEqual("foo", nestedMapResponse["a"], "nestedMap: a");
                            Assert.AreEqual(23, nestedMapResponse["b"], "nestedMap: b");
                            Assert.AreEqual(45, nestedMapResponse["c"], "nestedMap: c");

                            IDictionary grandChildMapResponse = nestedMapResponse["d"] as IDictionary;
                            Assert.IsNotNull(grandChildMapResponse, "Grand child map not returned.");
                            Assert.AreEqual(grandChildMap.Count, grandChildMapResponse.Count, "grandChildMap: Wrong number of elements");
                            Assert.AreEqual(grandChildMapResponse["x"], "abc", "grandChildMap: x");

                            IList grandChildList = grandChildMapResponse["y"] as IList;
                            Assert.IsNotNull(grandChildList, "Grand child list not returned.");
                            Assert.AreEqual(3, grandChildList.Count, "grandChildList: Wrong number of list elements.");
                            Assert.AreEqual("a", grandChildList[0], "grandChildList: a");
                            Assert.AreEqual("b", grandChildList[1], "grandChildList: b");
                            Assert.AreEqual("c", grandChildList[2], "grandChildList: c");

                            IList listFieldResponse = message.Body.GetList("listField");
                            Assert.IsNotNull(listFieldResponse, "Nested list not returned.");
                            Assert.AreEqual(3, listFieldResponse.Count, "listFieldResponse: Wrong number of list elements.");
                            Assert.AreEqual("a", listFieldResponse[0], "listFieldResponse: a");
                            Assert.AreEqual("b", listFieldResponse[1], "listFieldResponse: b");
                            Assert.AreEqual("c", listFieldResponse[2], "listFieldResponse: c");
                        }
                }
            }
        }
Example #49
0
        public void SendReceiveMessageProperties(MsgDeliveryMode deliveryMode)
        {
            using (IConnection connection = CreateConnection(TEST_CLIENT_ID + ":" + new Random().Next()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = SessionUtil.GetDestination(session, DESTINATION_NAME);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode   = deliveryMode;
                            producer.RequestTimeout = receiveTimeout;
                            IMessage request = session.CreateMessage();
                            request.Properties["a"] = a;
                            request.Properties["b"] = b;
                            request.Properties["c"] = c;
                            request.Properties["d"] = d;
                            request.Properties["e"] = e;
                            request.Properties["f"] = f;
                            request.Properties["g"] = g;
                            request.Properties["h"] = h;
                            request.Properties["i"] = i;
                            request.Properties["j"] = j;
                            request.Properties["k"] = k;
                            request.Properties["l"] = l;
                            request.Properties["m"] = m;
                            request.Properties["n"] = n;
                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                            Assert.AreEqual(ToHex(f), ToHex(message.Properties.GetLong("f")), "map entry: f as hex");

                            // use generic API to access entries
                            Assert.AreEqual(a.ToString(), message.Properties["a"], "generic map entry: a");
                            Assert.AreEqual(b.ToString(), message.Properties["b"], "generic map entry: b");
                            Assert.AreEqual(c.ToString(), message.Properties["c"], "generic map entry: c");
                            Assert.AreEqual(d.ToString(), message.Properties["d"], "generic map entry: d");
                            Assert.AreEqual(e.ToString(), message.Properties["e"], "generic map entry: e");
                            Assert.AreEqual(f.ToString(), message.Properties["f"], "generic map entry: f");
                            Assert.AreEqual(g.ToString(), message.Properties["g"], "generic map entry: g");
                            Assert.AreEqual(h.ToString(), message.Properties["h"], "generic map entry: h");
                            Assert.AreEqual(i.ToString(), message.Properties["i"], "generic map entry: i");
                            Assert.AreEqual(j.ToString(), message.Properties["j"], "generic map entry: j");
                            Assert.AreEqual(k.ToString(), message.Properties["k"], "generic map entry: k");
                            Assert.AreEqual(l.ToString(), message.Properties["l"], "generic map entry: l");
                            Assert.AreEqual(m.ToString(), message.Properties["m"], "generic map entry: m");
                            Assert.AreEqual(n.ToString(), message.Properties["n"], "generic map entry: n");

                            // use type safe APIs
                            Assert.AreEqual(a, message.Properties.GetBool("a"), "map entry: a");
                            Assert.AreEqual(b, message.Properties.GetByte("b"), "map entry: b");
                            Assert.AreEqual(c.ToString(), message.Properties.GetString("c"), "map entry: c");
                            Assert.AreEqual(d, message.Properties.GetShort("d"), "map entry: d");
                            Assert.AreEqual(e, message.Properties.GetInt("e"), "map entry: e");
                            Assert.AreEqual(f, message.Properties.GetLong("f"), "map entry: f");
                            Assert.AreEqual(g, message.Properties.GetString("g"), "map entry: g");
                            Assert.AreEqual(h, message.Properties.GetBool("h"), "map entry: h");
                            Assert.AreEqual(i, message.Properties.GetByte("i"), "map entry: i");
                            Assert.AreEqual(j, message.Properties.GetShort("j"), "map entry: j");
                            Assert.AreEqual(k, message.Properties.GetInt("k"), "map entry: k");
                            Assert.AreEqual(l, message.Properties.GetLong("l"), "map entry: l");
                            Assert.AreEqual(m, message.Properties.GetFloat("m"), "map entry: m");
                            Assert.AreEqual(n, message.Properties.GetDouble("n"), "map entry: n");
                        }
                }
            }
        }
Example #50
0
 public override void TestConsumerTransformer(
     [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
     MsgDeliveryMode deliveryMode)
 {
     base.TestConsumerTransformer(deliveryMode);
 }
Example #51
0
 public static void Send(this IMessage message, IMessageProducer producer, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     producer.Send(message, deliveryMode, priority, timeToLive);
 }
Example #52
0
 /// <summary>
 /// Sends the message to the default destination with the explicit QoS configuration.  The object must be serializable to XML.
 /// </summary>
 public static void Send(this IMessageProducer producer, object objMessage, Encoding encoding, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     producer.Send(producer.CreateXmlMessage(objMessage, encoding), deliveryMode, priority, timeToLive);
 }
 public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive)
 {
     throw new NotImplementedException();
 }
Example #54
0
        //[Test]
        public virtual void TestSendReceiveMessageProperties(
            //[Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)]
            MsgDeliveryMode deliveryMode, string testQueueRef)
        {
            using (IConnection connection = CreateConnection(GetTestClientId()))
            {
                connection.Start();
                using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge))
                {
                    IDestination destination = GetClearDestination(session, DestinationType.Queue, testQueueRef);
                    using (IMessageConsumer consumer = session.CreateConsumer(destination))
                        using (IMessageProducer producer = session.CreateProducer(destination))
                        {
                            producer.DeliveryMode = deliveryMode;
                            IMessage request = session.CreateMessage();
                            request.Properties["a"] = a;
                            request.Properties["b"] = b;
                            request.Properties["c"] = c;
                            request.Properties["d"] = d;
                            request.Properties["e"] = e;
                            request.Properties["f"] = f;
                            request.Properties["g"] = g;
                            request.Properties["h"] = h;
                            request.Properties["i"] = i;
                            request.Properties["j"] = j;
                            request.Properties["k"] = k;
                            request.Properties["l"] = l;
                            request.Properties["m"] = m;
                            request.Properties["n"] = n;

                            try
                            {
                                request.Properties["o"] = o;
                                Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
                            }
                            catch
                            {
                                // Expected
                            }

                            try
                            {
                                request.Properties.SetBytes("o", o);
                                Assert.Fail("Should not be able to add a Byte[] to the Properties of a Message.");
                            }
                            catch
                            {
                                // Expected
                            }

                            producer.Send(request);

                            IMessage message = consumer.Receive(receiveTimeout);
                            Assert.IsNotNull(message, "No message returned!");
                            Assert.AreEqual(request.Properties.Count, message.Properties.Count, "Invalid number of properties.");
                            Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match");
                            Assert.AreEqual(ToHex(f), ToHex(message.Properties.GetLong("f")), "map entry: f as hex");

                            // use generic API to access entries
                            // Perform a string only comparison here since some NMS providers are type limited and
                            // may return only a string instance from the generic [] accessor.  Each provider should
                            // further test this functionality to determine that the correct type is returned if
                            // it is capable of doing so.
                            Assert.AreEqual(a.ToString(), message.Properties["a"].ToString(), "generic map entry: a");
                            Assert.AreEqual(b.ToString(), message.Properties["b"].ToString(), "generic map entry: b");
                            Assert.AreEqual(c.ToString(), message.Properties["c"].ToString(), "generic map entry: c");
                            Assert.AreEqual(d.ToString(), message.Properties["d"].ToString(), "generic map entry: d");
                            Assert.AreEqual(e.ToString(), message.Properties["e"].ToString(), "generic map entry: e");
                            Assert.AreEqual(f.ToString(), message.Properties["f"].ToString(), "generic map entry: f");
                            Assert.AreEqual(g.ToString(), message.Properties["g"].ToString(), "generic map entry: g");
                            Assert.AreEqual(h.ToString(), message.Properties["h"].ToString(), "generic map entry: h");
                            Assert.AreEqual(i.ToString(), message.Properties["i"].ToString(), "generic map entry: i");
                            Assert.AreEqual(j.ToString(), message.Properties["j"].ToString(), "generic map entry: j");
                            Assert.AreEqual(k.ToString(), message.Properties["k"].ToString(), "generic map entry: k");
                            Assert.AreEqual(l.ToString(), message.Properties["l"].ToString(), "generic map entry: l");
                            Assert.AreEqual(m.ToString(), message.Properties["m"].ToString(), "generic map entry: m");
                            Assert.AreEqual(n.ToString(), message.Properties["n"].ToString(), "generic map entry: n");

                            // use type safe APIs
                            Assert.AreEqual(a, message.Properties.GetBool("a"), "map entry: a");
                            Assert.AreEqual(b, message.Properties.GetByte("b"), "map entry: b");
                            Assert.AreEqual(c, message.Properties.GetChar("c"), "map entry: c");
                            Assert.AreEqual(d, message.Properties.GetShort("d"), "map entry: d");
                            Assert.AreEqual(e, message.Properties.GetInt("e"), "map entry: e");
                            Assert.AreEqual(f, message.Properties.GetLong("f"), "map entry: f");
                            Assert.AreEqual(g, message.Properties.GetString("g"), "map entry: g");
                            Assert.AreEqual(h, message.Properties.GetBool("h"), "map entry: h");
                            Assert.AreEqual(i, message.Properties.GetByte("i"), "map entry: i");
                            Assert.AreEqual(j, message.Properties.GetShort("j"), "map entry: j");
                            Assert.AreEqual(k, message.Properties.GetInt("k"), "map entry: k");
                            Assert.AreEqual(l, message.Properties.GetLong("l"), "map entry: l");
                            Assert.AreEqual(m, message.Properties.GetFloat("m"), "map entry: m");
                            Assert.AreEqual(n, message.Properties.GetDouble("n"), "map entry: n");
                        }
                }
            }
        }
Example #55
0
 internal NmsProducer(INmsConnection connection, Destination destination, MsgDeliveryMode deliveryMode = MsgDeliveryMode.Persistent, bool synchronous = false)
     : this()
 {
     this.innerDestination = destination;
     this.Setup(connection, deliveryMode, synchronous);
 }