Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public void TestShallowCopy()
        {
            ActiveMQMessage msg1 = new ActiveMQMessage();

            msg1.NMSMessageId = nmsMessageID;
            ActiveMQMessage msg2 = (ActiveMQMessage)msg1.Clone();

            Assert.IsTrue(msg1 != msg2 && msg1.Equals(msg2));
        }
Esempio n. 3
0
        internal async Task DoSendAsync(ActiveMQDestination destination, ActiveMQMessage message,
                                        MessageProducer producer, MemoryUsage producerWindow, TimeSpan sendTimeout)
        {
            ActiveMQMessage msg = message;

            if (destination.IsTemporary && !connection.IsTempDestinationActive(destination as ActiveMQTempDestination))
            {
                throw new InvalidDestinationException("Cannot publish to a deleted Destination: " + destination);
            }

            if (IsTransacted)
            {
                DoStartTransaction();
                msg.TransactionId = TransactionContext.TransactionId;
            }

            msg.RedeliveryCounter = 0;
            msg.BrokerPath        = null;

            if (this.connection.CopyMessageOnSend)
            {
                msg = (ActiveMQMessage)msg.Clone();
            }

            msg.OnSend();
            msg.ProducerId = msg.MessageId.ProducerId;

            if (sendTimeout.TotalMilliseconds <= 0 && !msg.ResponseRequired && !connection.AlwaysSyncSend &&
                (!msg.Persistent || connection.AsyncSend || msg.TransactionId != null))
            {
                this.connection.Oneway(msg);

                if (producerWindow != null)
                {
                    // Since we defer lots of the marshaling till we hit the wire, this
                    // might not provide and accurate size. We may change over to doing
                    // more aggressive marshaling, to get more accurate sizes.. this is more
                    // important once users start using producer window flow control.
                    producerWindow.IncreaseUsage(msg.Size());
                }
            }
            else
            {
                if (sendTimeout.TotalMilliseconds > 0)
                {
                    await this.connection.SyncRequestAsync(msg, sendTimeout).Await();
                }
                else
                {
                    await this.connection.SyncRequestAsync(msg).Await();
                }
            }
        }