You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2019/07/09 07:57:06 UTC

[GitHub] [activemq-nms-amqp] cezarypiatekGC commented on a change in pull request #4: [WIP] Failover implementation

cezarypiatekGC commented on a change in pull request #4: [WIP] Failover implementation
URL: https://github.com/apache/activemq-nms-amqp/pull/4#discussion_r301098288
 
 

 ##########
 File path: src/NMS.AMQP/Provider/Amqp/Message/AmqpCodec.cs
 ##########
 @@ -0,0 +1,141 @@
+using System;
+using Amqp.Framing;
+using Amqp.Types;
+using Apache.NMS.AMQP.Message.Facade;
+using Apache.NMS.AMQP.Util;
+
+namespace Apache.NMS.AMQP.Provider.Amqp.Message
+{
+    public class AmqpCodec
+    {
+        public static INmsMessageFacade DecodeMessage(IAmqpConsumer consumer, global::Amqp.Message amqpMessage)
+        {
+            // First we try the easy way, if the annotation is there we don't have to work hard.
+            AmqpNmsMessageFacade result = CreateFromMsgAnnotation(amqpMessage.MessageAnnotations);
+            if (result == null)
+            {
+                // Next, match specific section structures and content types
+                result = CreateWithoutAnnotation(amqpMessage.BodySection, amqpMessage.Properties);
+            }
+
+            if (result != null)
+            {
+                result.Initialize(consumer, amqpMessage);
+                return result;
+            }
+
+            throw new NMSException("Could not create a NMS message from incoming message");
+        }
+
+        private static AmqpNmsMessageFacade CreateFromMsgAnnotation(MessageAnnotations messageAnnotations)
+        {
+            object annotation = messageAnnotations?[SymbolUtil.JMSX_OPT_MSG_TYPE];
+
+            if (annotation != null)
+            {
+                byte type = Convert.ToByte(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;
+        }
+
+        private static AmqpNmsMessageFacade CreateWithoutAnnotation(RestrictedDescribed body, Properties properties)
+        {
+            Symbol contentType = GetContentType(properties);
+
+            if (body == null)
 
 Review comment:
   Branches for `body == null` and `body is Data` do the same thing. Looks like an unnecessary duplication.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services