HavretGC commented on a change in pull request #4: [WIP] Failover implementation
URL: https://github.com/apache/activemq-nms-amqp/pull/4#discussion_r302187548
##########
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:
Fixed
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services