DoSend() private method

private DoSend ( ActiveMQMessage message, MessageProducer producer, MemoryUsage producerWindow, TimeSpan sendTimeout ) : void
message ActiveMQMessage
producer MessageProducer
producerWindow MemoryUsage
sendTimeout TimeSpan
return void
        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();
            }

            ActiveMQMessage activeMessage = (ActiveMQMessage)message;

            if (!disableMessageID)
            {
                MessageId id = new MessageId();
                id.ProducerId           = info.ProducerId;
                id.ProducerSequenceId   = Interlocked.Increment(ref messageCounter);
                activeMessage.MessageId = id;
            }

            activeMessage.ProducerId      = info.ProducerId;
            activeMessage.FromDestination = destination;
            activeMessage.NMSDeliveryMode = deliveryMode;
            activeMessage.NMSPriority     = priority;

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

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

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

                if (session.Transacted)
                {
                    session.DoStartTransaction();
                    activeMessage.TransactionId = session.TransactionContext.TransactionId;
                }

                session.DoSend(activeMessage, this.RequestTimeout);
            }
        }
        protected void Send(IDestination destination, IMessage message, bool persistent, byte priority, TimeSpan timeToLive, bool specifiedTimeToLive)
        {
            CheckClosed();
            ActiveMQMessage activeMessage = (ActiveMQMessage)message;

            if (!disableMessageID)
            {
                MessageId id = new MessageId();
                id.ProducerId = info.ProducerId;
                lock (this)
                {
                    id.ProducerSequenceId = ++messageCounter;
                }

                activeMessage.MessageId = id;
            }

            activeMessage.ProducerId      = info.ProducerId;
            activeMessage.FromDestination = destination;
            activeMessage.NMSPersistent   = persistent;
            activeMessage.NMSPriority     = priority;

            if (session.Transacted)
            {
                session.DoStartTransaction();
                activeMessage.TransactionId = session.TransactionContext.TransactionId;
            }

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

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

            session.DoSend(activeMessage, this.RequestTimeout);
        }
Esempio n. 3
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;

            // Ensure that the source message contains the NMSMessageId of the transformed
            // message for correlation purposes.
            if (!ReferenceEquals(message, activeMessage))
            {
                message.NMSMessageId = activeMessage.NMSMessageId;
            }

            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(dest, activeMessage, this, this.usage, this.RequestTimeout);
            }
        }