protected AbstractQmsMessage CreateMessageWithBody(long messageNbr,
                                                           ContentHeaderBody contentHeader,
                                                           IList bodies)
        {
            ByteBuffer data;

            // we optimise the non-fragmented case to avoid copying
            if (bodies != null && bodies.Count == 1)
            {
                _logger.Debug("Non-fragmented message body (bodySize=" + contentHeader.BodySize + ")");
                data = ((ContentBody)bodies[0]).Payload;
            }
            else
            {
                _logger.Debug("Fragmented message body (" + bodies.Count + " frames, bodySize=" + contentHeader.BodySize + ")");
                data = ByteBuffer.Allocate((int)contentHeader.BodySize); // XXX: Is cast a problem?
                foreach (ContentBody body in bodies)
                {
                    data.Put(body.Payload);
                    //body.Payload.Release();
                }

                data.Flip();
            }
            _logger.Debug("Creating message from buffer with position=" + data.Position + " and remaining=" + data.Remaining);

            return(CreateMessage(messageNbr, data, contentHeader));
        }
        private void SendImpl(string exchangeName, string routingKey, AbstractQmsMessage message, DeliveryMode deliveryMode, int priority, uint timeToLive, bool mandatory, bool immediate)
        {
            // todo: handle session access ticket
            AMQFrame publishFrame = BasicPublishBody.CreateAMQFrame(
                _channel.ChannelId, 0, exchangeName,
                routingKey, mandatory, immediate
                );

            // fix message properties
            if (!_disableTimestamps)
            {
                message.Timestamp = DateTime.UtcNow.Ticks;
                if (timeToLive != 0)
                {
                    message.Expiration = message.Timestamp + timeToLive;
                }
            }
            else
            {
                message.Expiration = 0;
            }
            message.DeliveryMode = deliveryMode;
            message.Priority     = (byte)priority;

            ByteBuffer payload       = message.Data;
            int        payloadLength = payload.Limit;

            ContentBody[] contentBodies = CreateContentBodies(payload);
            AMQFrame[]    frames        = new AMQFrame[2 + contentBodies.Length];
            for (int i = 0; i < contentBodies.Length; i++)
            {
                frames[2 + i] = ContentBody.CreateAMQFrame(_channelId, contentBodies[i]);
            }
            if (contentBodies.Length > 0 && _logger.IsDebugEnabled)
            {
                _logger.Debug(string.Format("Sending content body frames to {{exchangeName={0} routingKey={1}}}", exchangeName, routingKey));
            }

            // weight argument of zero indicates no child content headers, just bodies
            AMQFrame contentHeaderFrame = ContentHeaderBody.CreateAMQFrame(
                _channelId, AmqChannel.BASIC_CONTENT_TYPE, 0,
                message.ContentHeaderProperties, (uint)payloadLength
                );

            if (_logger.IsDebugEnabled)
            {
                _logger.Debug(string.Format("Sending content header frame to  {{exchangeName={0} routingKey={1}}}", exchangeName, routingKey));
            }

            frames[0] = publishFrame;
            frames[1] = contentHeaderFrame;
            CompositeAMQDataBlock compositeFrame = new CompositeAMQDataBlock(frames);

            lock (_channel.Connection.FailoverMutex)
            {
                _channel.Connection.ProtocolWriter.Write(compositeFrame);
            }
        }
        public AbstractQmsMessage CreateMessage(long messageNbr, bool redelivered,
                                                ContentHeaderBody contentHeader,
                                                IList bodies)
        {
            AbstractQmsMessage msg = CreateMessageWithBody(messageNbr, contentHeader, bodies);

            msg.Redelivered = redelivered;
            return(msg);
        }
        /// <summary>
        /// Create a message. This looks up the MIME type from the content header and instantiates the appropriate
        /// concrete message type.
        /// </summary>
        /// <param name="messageNbr">the AMQ message id</param>
        /// <param name="redelivered">true if redelivered</param>
        /// <param name="contentHeader">the content header that was received</param>
        /// <param name="bodies">a list of ContentBody instances</param>
        /// <returns>the message.</returns>
        /// <exception cref="AMQException"/>
        /// <exception cref="QpidException"/>
        public AbstractQmsMessage CreateMessage(long messageNbr, bool redelivered,
                                                ContentHeaderBody contentHeader,
                                                IList bodies)
        {
            BasicContentHeaderProperties properties = (BasicContentHeaderProperties)contentHeader.Properties;

            if (properties.ContentType == null)
            {
                properties.ContentType = "";
            }

            IMessageFactory mf = GetFactory(properties.ContentType);

            return(mf.CreateMessage(messageNbr, redelivered, contentHeader, bodies));
        }
        public void MessageContentHeaderReceived(ushort channelId, ContentHeaderBody contentHeader)
        {
            UnprocessedMessage msg = (UnprocessedMessage)_channelId2UnprocessedMsgMap[channelId];

            if (msg == null)
            {
                throw new AMQException("Error: received content header without having received a JMSDeliver frame first");
            }
            if (msg.ContentHeader != null)
            {
                throw new AMQException("Error: received duplicate content header or did not receive correct number of content body frames");
            }
            msg.ContentHeader = contentHeader;
            if (contentHeader.BodySize == 0)
            {
                DeliverMessageToAMQSession(channelId, msg);
            }
        }
        //protected override AbstractQmsMessage CreateMessageWithBody(long messageNbr,
        //                                                            ContentHeaderBody contentHeader,
        //                                                            IList bodies)
        //{
        //    byte[] data;

        //    // we optimise the non-fragmented case to avoid copying
        //    if (bodies != null && bodies.Count == 1)
        //    {
        //        data = ((ContentBody)bodies[0]).Payload;
        //    }
        //    else
        //    {
        //        data = new byte[(long)contentHeader.BodySize];
        //        int currentPosition = 0;
        //        foreach (ContentBody cb in bodies)
        //        {
        //            Array.Copy(cb.Payload, 0, data, currentPosition, cb.Payload.Length);
        //            currentPosition += cb.Payload.Length;
        //        }
        //    }

        //    return new QpidBytesMessage(messageNbr, data, contentHeader);
        //}

        //public override AbstractQmsMessage CreateMessage()
        //{
        //    return new QpidBytesMessage();
        //}

        protected override AbstractQmsMessage CreateMessage(long deliveryTag, ByteBuffer data, ContentHeaderBody contentHeader)
        {
            return(new QpidBytesMessage(deliveryTag, contentHeader, data));
        }
 protected abstract AbstractQmsMessage CreateMessage(long messageNbr, ByteBuffer data, ContentHeaderBody contentHeader);
Esempio n. 8
0
 internal QpidBytesMessage(long messageNbr, ContentHeaderBody contentHeader, ByteBuffer data)
 // TODO: this casting is ugly. Need to review whole ContentHeaderBody idea
     : base(messageNbr, (BasicContentHeaderProperties)contentHeader.Properties, data)
 {
 }
 protected override AbstractQmsMessage CreateMessage(long deliveryTag, ByteBuffer data, ContentHeaderBody contentHeader)
 {
     return(new QpidTextMessage(deliveryTag, (BasicContentHeaderProperties)contentHeader.Properties, data));
 }