private static AmqpNmsMessageFacade CreateFromMsgAnnotation(MessageAnnotations messageAnnotations)
        {
            object annotation = messageAnnotations?[SymbolUtil.JMSX_OPT_MSG_TYPE];

            if (annotation != null)
            {
                sbyte type = Convert.ToSByte(annotation);
                switch (type)
                {
                case MessageSupport.JMS_TYPE_MSG:
                    return(new AmqpNmsMessageFacade());

                case MessageSupport.JMS_TYPE_BYTE:
                    return(new AmqpNmsBytesMessageFacade());

                case MessageSupport.JMS_TYPE_TXT:
                    return(new AmqpNmsTextMessageFacade());

                case MessageSupport.JMS_TYPE_OBJ:
                    return(new AmqpNmsObjectMessageFacade());

                case MessageSupport.JMS_TYPE_STRM:
                    return(new AmqpNmsStreamMessageFacade());

                case MessageSupport.JMS_TYPE_MAP:
                    return(new AmqpNmsMapMessageFacade());

                default:
                    throw new NMSException("Invalid Message Type annotation value found in message: " + annotation);
                }
            }

            return(null);
        }
예제 #2
0
        public void TestNewMessageToSendDoesNotContainMessageTypeAnnotation()
        {
            AmqpNmsStreamMessageFacade amqpNmsStreamMessageFacade = CreateNewStreamMessageFacade();
            MessageAnnotations         annotations = amqpNmsStreamMessageFacade.MessageAnnotations;

            Assert.Null(annotations, "MessageAnnotations section was present");
            Assert.AreEqual(MessageSupport.JMS_TYPE_STRM, amqpNmsStreamMessageFacade.JmsMessageType);
        }
예제 #3
0
 void WriteMessageAnnotations(ref MessageAnnotations annotations, MessageAnnotations current, ByteBuffer buffer)
 {
     if (annotations != null && current != null)
     {
         this.Merge(current.Map, annotations.Map);
         annotations.Encode(buffer);
         annotations = null;
     }
 }
예제 #4
0
        void DeepCopy(AmqpMessage source)
        {
            if (source.header != null)
            {
                this.header               = new Header();
                this.header.Durable       = source.header.Durable;
                this.header.Priority      = source.header.Priority;
                this.header.Ttl           = source.header.Ttl;
                this.header.FirstAcquirer = source.header.FirstAcquirer;
                this.header.DeliveryCount = source.header.DeliveryCount;
            }

            if (source.deliveryAnnotations != null)
            {
                this.deliveryAnnotations = new DeliveryAnnotations();
                this.deliveryAnnotations.Map.Merge(source.deliveryAnnotations.Map);
            }

            if (source.messageAnnotations != null)
            {
                this.messageAnnotations = new MessageAnnotations();
                this.messageAnnotations.Map.Merge(source.messageAnnotations.Map);
            }

            if (source.applicationProperties != null)
            {
                this.applicationProperties = new ApplicationProperties();
                this.applicationProperties.Map.Merge(source.applicationProperties.Map);
            }

            if (source.properties != null)
            {
                this.properties                    = new Properties();
                this.properties.MessageId          = source.properties.MessageId;
                this.properties.UserId             = source.properties.UserId;
                this.properties.To                 = source.properties.To;
                this.properties.Subject            = source.properties.Subject;
                this.properties.ReplyTo            = source.properties.ReplyTo;
                this.properties.CorrelationId      = source.properties.CorrelationId;
                this.properties.ContentType        = source.properties.ContentType;
                this.properties.ContentEncoding    = source.properties.ContentEncoding;
                this.properties.AbsoluteExpiryTime = source.properties.AbsoluteExpiryTime;
                this.properties.CreationTime       = source.properties.CreationTime;
                this.properties.GroupId            = source.properties.GroupId;
                this.properties.GroupSequence      = source.properties.GroupSequence;
                this.properties.ReplyToGroupId     = source.properties.ReplyToGroupId;
            }

            if (source.footer != null)
            {
                this.footer = new Footer();
                this.footer.Map.Merge(source.footer.Map);
            }

            this.sectionFlags |= (source.sectionFlags & SectionFlag.NonBody);
        }
예제 #5
0
 void ShadowCopy(AmqpMessage source)
 {
     this.header = source.header;
     this.deliveryAnnotations   = source.deliveryAnnotations;
     this.messageAnnotations    = source.messageAnnotations;
     this.properties            = source.properties;
     this.applicationProperties = source.applicationProperties;
     this.footer        = source.footer;
     this.sectionFlags |= (source.sectionFlags & SectionFlag.NonBody);
 }
        public void TestNewMessageToSendDoesNotContainMessageTypeAnnotation()
        {
            AmqpNmsTextMessageFacade textMessageFacade = CreateNewTextMessageFacade();


            MessageAnnotations annotations = textMessageFacade.MessageAnnotations;

            Assert.Null(annotations, "MessageAnnotations section was present");
            Assert.AreEqual(MessageSupport.JMS_TYPE_TXT, textMessageFacade.JmsMsgType);
        }
        public static AMQPSection getSection(IByteBuffer buf)
        {
            TLVAmqp value = TLVFactory.getTlv(buf);

            AMQPSection section = null;

            Byte         byteCode = value.Constructor.getDescriptorCode().Value;
            SectionCodes code     = (SectionCodes)byteCode;

            switch (code)
            {
            case SectionCodes.APPLICATION_PROPERTIES:
                section = new ApplicationProperties();
                break;

            case SectionCodes.DATA:
                section = new AMQPData();
                break;

            case SectionCodes.DELIVERY_ANNOTATIONS:
                section = new DeliveryAnnotations();
                break;

            case SectionCodes.FOOTER:
                section = new AMQPFooter();
                break;

            case SectionCodes.HEADER:
                section = new MessageHeader();
                break;

            case SectionCodes.MESSAGE_ANNOTATIONS:
                section = new MessageAnnotations();
                break;

            case SectionCodes.PROPERTIES:
                section = new AMQPProperties();
                break;

            case SectionCodes.SEQUENCE:
                section = new AMQPSequence();
                break;

            case SectionCodes.VALUE:
                section = new AMQPValue();
                break;

            default:
                throw new MalformedMessageException("Received header with unrecognized message section code");
            }

            section.fill(value);

            return(section);
        }
예제 #8
0
        public static AmqpMessage BrokerGetMessage(BrokeredMessage brokeredMessage)
        {
            AmqpMessage messageId = null;
            bool        flag      = true;

            if (brokeredMessage.MessageFormat == BrokeredMessageFormat.PassthroughAmqp)
            {
                flag      = false;
                messageId = AmqpMessage.CreateAmqpStreamMessage((BufferListStream)brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Amqp)
            {
                messageId = AmqpMessage.CreateAmqpStreamMessage(brokeredMessage.RawHeaderStream, brokeredMessage.BodyStream, true);
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.AmqpEventData)
            {
                flag = false;
                BufferListStream bufferListStream = BufferListStream.Create(brokeredMessage.BodyStream, 512, true);
                messageId = AmqpMessage.CreateOutputMessage(bufferListStream, true);
                MessageAnnotations messageAnnotations = messageId.MessageAnnotations;
                messageAnnotations.Map["x-opt-sequence-number"] = brokeredMessage.SequenceNumber;
                Annotations map        = messageAnnotations.Map;
                AmqpSymbol  amqpSymbol = "x-opt-offset";
                long        offset     = brokeredMessage.Offset;
                map[amqpSymbol] = offset.ToString(NumberFormatInfo.InvariantInfo);
                messageAnnotations.Map["x-opt-enqueued-time"] = brokeredMessage.EnqueuedTimeUtc;
                if (!string.IsNullOrEmpty(brokeredMessage.Publisher))
                {
                    messageAnnotations.Map["x-opt-publisher"]     = brokeredMessage.Publisher;
                    messageAnnotations.Map["x-opt-partition-key"] = brokeredMessage.Publisher;
                }
            }
            else if (brokeredMessage.MessageFormat == BrokeredMessageFormat.Sbmp)
            {
                brokeredMessage.SetPropertiesAsModifiedByBroker();
                messageId = MessageConverter.CreateAmqpMessageFromSbmpMessage(brokeredMessage);
                messageId.Properties.MessageId      = brokeredMessage.MessageId;
                messageId.Properties.CorrelationId  = brokeredMessage.CorrelationId;
                messageId.Properties.ContentType    = brokeredMessage.ContentType;
                messageId.Properties.Subject        = brokeredMessage.Label;
                messageId.Properties.To             = brokeredMessage.To;
                messageId.Properties.ReplyTo        = brokeredMessage.ReplyTo;
                messageId.Properties.GroupId        = brokeredMessage.SessionId;
                messageId.Properties.ReplyToGroupId = brokeredMessage.ReplyToSessionId;
            }
            if (flag)
            {
                MessageConverter.UpdateAmqpMessageHeadersAndProperties(messageId, brokeredMessage, true);
            }
            return(messageId);
        }
예제 #9
0
 protected void InitMessageAnnontations()
 {
     if (this.messageAnnontations == null && this.message.MessageAnnotations == null)
     {
         this.messageAnnontations        = new MessageAnnotations();
         this.message.MessageAnnotations = messageAnnontations;
     }
     else if (this.messageAnnontations == null && this.message.MessageAnnotations != null)
     {
         this.messageAnnontations = this.message.MessageAnnotations;
     }
     else if (this.messageAnnontations != null && this.message.MessageAnnotations == null)
     {
         this.message.MessageAnnotations = this.messageAnnontations;
     }
 }
예제 #10
0
            void UpdateMessageAnnotations(MessageAnnotations messageAnnotations)
            {
                if (messageAnnotations != null)
                {
                    if (this.messageAnnotations == null)
                    {
                        this.MessageAnnotations = messageAnnotations;
                    }
                    else
                    {
                        foreach (KeyValuePair <MapKey, object> pair in this.messageAnnotations.Map)
                        {
                            messageAnnotations.Map[pair.Key] = pair.Value;
                        }

                        this.messageAnnotations = messageAnnotations;
                    }
                }
            }
예제 #11
0
            void CheckModified(ByteBuffer oldBuf)
            {
                if (this.failedCount == 0 && this.MessageAnnotations == null)
                {
                    return;
                }
                ByteBuffer         newBuf      = new ByteBuffer(oldBuf.Size, true);
                Header             header      = new Header();
                MessageAnnotations annotations = this.MessageAnnotations;
                int offset = oldBuf.Offset;

                while (oldBuf.Length > 0)
                {
                    offset = oldBuf.Offset;
                    var described = (RestrictedDescribed)Encoder.ReadDescribed(oldBuf, Encoder.ReadFormatCode(buffer));
                    if (described.Descriptor.Code == 0x70UL)
                    {
                        header = (Header)described;
                        this.WriteHeader(ref header, newBuf);
                    }
                    else if (described.Descriptor.Code == 0x71UL)
                    {
                        this.WriteHeader(ref header, newBuf);
                        AmqpBitConverter.WriteBytes(newBuf, oldBuf.Buffer, offset, oldBuf.Offset - offset);
                    }
                    else if (described.Descriptor.Code == 0x72UL)
                    {
                        this.WriteHeader(ref header, newBuf);
                        this.WriteMessageAnnotations(ref annotations, (MessageAnnotations)described, newBuf);
                    }
                    else
                    {
                        this.WriteHeader(ref header, newBuf);
                        this.WriteMessageAnnotations(ref annotations, null, newBuf);
                        AmqpBitConverter.WriteBytes(newBuf, oldBuf.Buffer, offset, oldBuf.WritePos - offset);
                        break;
                    }
                }
                this.buffer        = newBuf;
                this.messageOffset = 0;
            }
예제 #12
0
        private static void SetAnnotationFromDestination(Symbol key, IDestination destination, MessageAnnotations annotations)
        {
            byte?typeValue = ToTypeAnnotation(destination);

            if (typeValue == null)
            {
                annotations.Map.Remove(key);
            }
            else
            {
                annotations.Map[key] = typeValue;
            }
        }
예제 #13
0
 public static void SetReplyToAnnotationFromDestination(IDestination destination, MessageAnnotations annotations)
 => SetAnnotationFromDestination(SymbolUtil.JMSX_OPT_REPLY_TO, destination, annotations);
예제 #14
0
 public static void SetToAnnotationFromDestination(IDestination destination, MessageAnnotations annotations)
 => SetAnnotationFromDestination(SymbolUtil.JMSX_OPT_DEST, destination, annotations);
예제 #15
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SenderOptions() : base()
        {
            //default values
            this.Id              = String.Empty;
            this.To              = String.Empty;
            this.ReplyTo         = String.Empty;
            this.Subject         = String.Empty;
            this.Durable         = false;
            this.Ttl             = 0;
            this.Priority        = 0;
            this.CorrelationId   = String.Empty;
            this.UserId          = null;
            this.MsgContentType  = String.Empty;
            this.Content         = String.Empty;
            this.ContentFromFile = String.Empty;
            this.ContentType     = "string";
            this.PropertyType    = "string";
            this.GroupSequence   = 0;

            this.Properties         = new Dictionary <string, object>();
            this.ListContent        = new List();
            this.MapContent         = new Map();
            this.MessageAnnotations = new MessageAnnotations();

            //add options
            this.Add("msg-id=", "use the supplied id instead of generating one",
                     (string id) => { this.Id = id; });
            this.Add("msg-to=", "amqp:to in message header",
                     (string to) => { this.To = to; });
            this.Add("msg-reply-to=", "specify reply-to address",
                     (string replyTo) => { this.ReplyTo = replyTo; });
            this.Add("msg-subject=", "specify reply-to subject",
                     (string subject) => { this.Subject = subject; });
            this.Add("msg-property=", "specify reply-to property",
                     (string property) => {
                char[] delimiters = { '=', '~' };
                string[] pair     = property.Split(delimiters);
                int valueIndex    = pair.Length == 2 ? 1 : 2;
                if (pair.Length == 2 || pair.Length == 3)
                {
                    double doubleVal;
                    int intVal;
                    bool boolVal;
                    if (int.TryParse(pair[valueIndex], out intVal))
                    {
                        this.Properties.Add(pair[0], intVal);
                    }
                    else if (double.TryParse(pair[valueIndex], out doubleVal))
                    {
                        this.Properties.Add(pair[0], doubleVal);
                    }
                    else if (Boolean.TryParse(pair[valueIndex], out boolVal))
                    {
                        this.Properties.Add(pair[0], boolVal);
                    }
                    else
                    {
                        this.Properties.Add(pair[0], pair[valueIndex]);
                    }
                }
                else
                {
                    throw new ArgumentException();
                }
            });
            this.Add("property-type=", "specify message property type (overrides auto-cast feature)",
                     (string propertyType) => { this.PropertyType = propertyType; });
            this.Add("msg-durable=", "send durable messages yes/no",
                     (string durable) => { this.Durable = ParseBoolOption(durable); });
            this.Add("msg-ttl=", "message time-to-live (ms)",
                     (uint ttl) => { this.Ttl = ttl; });
            this.Add("msg-priority=", "message priority",
                     (byte priority) => { this.Priority = priority; });
            this.Add("msg-correlation-id=", "message correlation id",
                     (string correlationId) => { this.CorrelationId = correlationId; });
            this.Add("msg-user-id=", "message user id",
                     (string userId) => {
                char[] uid       = userId.ToCharArray();
                List <byte> uidl = new List <byte>();
                foreach (char c in uid)
                {
                    uidl.Add((byte)c);
                }
                this.UserId = uidl.ToArray();
            });
            this.Add("msg-group-id=", "amqp message group id",
                     (string groupId) => { this.GroupId = groupId; });
            this.Add("msg-group-seq=", "amqp message group sequence",
                     (int groupSequence) => { this.GroupSequence = groupSequence; });
            this.Add("msg-reply-to-group-id=", "amqp message reply to group id",
                     (string replyToGroupId) => { this.ReplyToGroupId = replyToGroupId; });
            this.Add("msg-content-type=", "message content type; values string, int, long, float",
                     (string contentType) => { this.ContentType = contentType; });
            this.Add("msg-content=", "specify a content",
                     (string content) => { this.Content = content; });
            this.Add("L|msg-content-list-item=", "specify a multiple entries content",
                     (string listItem) => {
                this.ListContent.Add(listItem);
            });
            this.Add("M|msg-content-map-item=", "KEY=VALUE specify a map content",
                     (string mapItem) => {
                char[] delimiters = { '=', '~' };
                string[] pair     = mapItem.Split(delimiters);
                if (pair.Length == 2)
                {
                    this.MapContent.Add(pair[0], pair[1]);
                }
                else if (pair.Length == 3)
                {
                    this.MapContent.Add(pair[0], pair[2]);
                }
                else
                {
                    throw new ArgumentException();
                }
            });
            this.Add("msg-content-from-file=", "specify file name to load the content from",
                     (string path) => { this.ContentFromFile = ReadInputFile(path); });
            this.Add("msg-annotation=", "specify amqp properties",
                     (string annotation) => {
                char[] delimiters = { '=', '~' };
                string[] pair     = annotation.Split(delimiters);
                if (pair.Length == 2)
                {
                    double doubleVal;
                    bool boolVal;
                    if (double.TryParse(pair[1], out doubleVal))
                    {
                        this.MessageAnnotations[new Symbol(pair[0])] = doubleVal;
                    }
                    else if (Boolean.TryParse(pair[1], out boolVal))
                    {
                        this.MessageAnnotations[new Symbol(pair[0])] = boolVal;
                    }
                    else
                    {
                        this.MessageAnnotations[new Symbol(pair[0])] = pair[1];
                    }
                }
                else
                {
                    throw new ArgumentException();
                }
            });
        }
예제 #16
0
        /// <summary>
        /// Constructor
        /// </summary>
        public SenderOptions() : base()
        {
            //default values
            this.Id              = String.Empty;
            this.To              = String.Empty;
            this.ReplyTo         = String.Empty;
            this.Subject         = String.Empty;
            this.Durable         = null;
            this.Ttl             = null;
            this.Priority        = null;
            this.CorrelationId   = String.Empty;
            this.UserId          = null;
            this.MsgContentType  = String.Empty;
            this.Content         = String.Empty;
            this.ContentFromFile = String.Empty;
            this.ContentType     = "string";
            this.PropertyType    = "string";
            this.GroupSequence   = 0;

            this.Properties         = new Dictionary <string, object>();
            this.ListContent        = new List();
            this.MapContent         = new Map();
            this.MessageAnnotations = new MessageAnnotations();

            //add options
            this.Add("msg-id=", "use the supplied id instead of generating one",
                     (string id) => { this.Id = id; });
            this.Add("msg-to=", "amqp:to in message header",
                     (string to) => { this.To = to; });
            this.Add("msg-reply-to=", "specify reply-to address",
                     (string replyTo) => { this.ReplyTo = replyTo; });
            this.Add("msg-subject=", "specify reply-to subject",
                     (string subject) => { this.Subject = subject; });
            this.Add("msg-property=", "specify reply-to property",
                     (string property) => {
                var(key, value) = ParseItem(property);
                this.Properties.Add(key, value);
            });
            this.Add("property-type=", "specify message property type (overrides auto-cast feature)",
                     (string propertyType) => { this.PropertyType = propertyType; });
            this.Add("msg-durable=", "send durable messages yes/no",
                     (string durable) => { this.Durable = ParseBoolOption(durable); });
            this.Add("msg-ttl=", "message time-to-live (ms)",
                     (uint ttl) => { this.Ttl = ttl; });
            this.Add("msg-priority=", "message priority",
                     (byte priority) => { this.Priority = priority; });
            this.Add("msg-correlation-id=", "message correlation id",
                     (string correlationId) => { this.CorrelationId = correlationId; });
            this.Add("msg-user-id=", "message user id",
                     (string userId) => {
                char[] uid       = userId.ToCharArray();
                List <byte> uidl = new List <byte>();
                foreach (char c in uid)
                {
                    uidl.Add((byte)c);
                }
                this.UserId = uidl.ToArray();
            });
            this.Add("msg-group-id=", "amqp message group id",
                     (string groupId) => { this.GroupId = groupId; });
            this.Add("msg-group-seq=", "amqp message group sequence",
                     (int groupSequence) => { this.GroupSequence = groupSequence; });
            this.Add("msg-reply-to-group-id=", "amqp message reply to group id",
                     (string replyToGroupId) => { this.ReplyToGroupId = replyToGroupId; });
            this.Add("content-type=|msg-content-type=", "message content type; values string, int, long, float",
                     (string contentType) => { this.ContentType = contentType; });
            this.Add("msg-content=", "specify a content",
                     (string content) => { this.Content = content; });
            this.Add("L|msg-content-list-item=", "specify a multiple entries content",
                     (string listItem) => {
                this.ListContent.Add(ParseValue(listItem));
            });
            this.Add("M|msg-content-map-item=", "KEY=VALUE specify a map content",
                     (string mapItem) => {
                var(key, value) = ParseItem(mapItem);
                this.MapContent.Add(key, value);
            });
            this.Add("msg-content-from-file=", "specify file name to load the content from",
                     (string path) => { this.ContentFromFile = ReadInputFile(path); });
            this.Add("msg-annotation=", "specify amqp properties",
                     (string annotation) => {
                var(key, value) = ParseItem(annotation);
                this.MessageAnnotations[new Symbol(key)] = value;
            });
        }