You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2014/10/09 01:17:41 UTC

svn commit: r1630251 - in /activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp: BaseMessage.cs MessageConsumer.cs MessageProducer.cs Session.cs

Author: jgomes
Date: Wed Oct  8 23:17:41 2014
New Revision: 1630251

URL: http://svn.apache.org/r1630251
Log:
Fix serializing/deserializing the message properties. Use the existing PrimitiveMap marshal/unmarshal functions.
Add additional exception handling in the MessageConsumer to pass the BadConsumerTest unit test.
Fixes [AMQNET-491]. (See https://issues.apache.org/jira/browse/AMQNET-491)

Modified:
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/BaseMessage.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageConsumer.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageProducer.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/BaseMessage.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/BaseMessage.cs?rev=1630251&r1=1630250&r2=1630251&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/BaseMessage.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/BaseMessage.cs Wed Oct  8 23:17:41 2014
@@ -84,6 +84,11 @@ namespace Apache.NMS.ZMQ
 			get { return propertiesMap; }
 		}
 
+		internal PrimitiveMap PropertiesMap
+		{
+			get { return propertiesMap; }
+			set { propertiesMap = value; }
+		}
 
 		// NMS headers
 

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageConsumer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageConsumer.cs?rev=1630251&r1=1630250&r2=1630251&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageConsumer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageConsumer.cs Wed Oct  8 23:17:41 2014
@@ -53,13 +53,35 @@ namespace Apache.NMS.ZMQ
 		{
 			// UNUSED_PARAM(selector);		// Selectors are not currently supported
 
-			if(null == sess.Connection.Context)
+			if(null == sess
+				|| null == sess.Connection
+				|| null == sess.Connection.Context)
 			{
 				throw new NMSConnectionException();
 			}
 
+			Destination theDest = dest as Destination;
+
+			if(null == theDest)
+			{
+				throw new InvalidDestinationException("Consumer cannot receive on Null Destinations.");
+			}
+			else if(null == theDest.Name)
+			{
+				throw new InvalidDestinationException("The destination object was not given a physical name.");
+			}
+			else if(theDest.IsTemporary)
+			{
+				String physicalName = theDest.Name;
+
+				if(String.IsNullOrEmpty(physicalName))
+				{
+					throw new InvalidDestinationException("Physical name of Destination should be valid: " + theDest);
+				}
+			}
+
 			this.session = sess;
-			this.destination = (Destination) dest;
+			this.destination = theDest;
 			this.rawDestinationName = Destination.encoding.GetBytes(this.destination.Name);
 			this.acknowledgementMode = ackMode;
 		}
@@ -268,7 +290,7 @@ namespace Apache.NMS.ZMQ
 		/// </returns>
 		protected virtual IMessage ToNmsMessage(byte[] msgData)
 		{
-			IMessage nmsMessage = null;
+			BaseMessage nmsMessage = null;
 			int messageType = WireFormat.MT_UNKNOWN;
 			int fieldType = WireFormat.MFT_NONE;
 			DateTime messageTimestamp = DateTime.UtcNow;
@@ -278,7 +300,7 @@ namespace Apache.NMS.ZMQ
 			MsgDeliveryMode messageDeliveryMode = MsgDeliveryMode.NonPersistent;
 			MsgPriority messagePriority = MsgPriority.Normal;
 			TimeSpan messageTimeToLive = TimeSpan.FromTicks(0);
-			IPrimitiveMap messageProperties = null;
+			byte[] messageProperties = null;
 			int fieldLen;
 			int index = 0;
 			string messageID = string.Empty;
@@ -338,16 +360,10 @@ namespace Apache.NMS.ZMQ
 
 					case WireFormat.MFT_HEADERS:
 						fieldLen = ReadInt(msgData, ref index);
-						int numProperties = ReadInt(msgData, ref index);
-						if(numProperties > 0)
+						messageProperties = new byte[fieldLen];
+						for(int propIndex = 0; propIndex < fieldLen; propIndex++, index++)
 						{
-							messageProperties = new PrimitiveMap();
-							while(numProperties-- > 0)
-							{
-								string propertyKey = ReadString(msgData, ref index);
-								byte[] propertyVal = ReadBytes(msgData, ref index);
-								messageProperties.SetBytes(propertyKey, propertyVal);
-							}
+							messageProperties[propIndex] = msgData[index];
 						}
 						break;
 
@@ -411,10 +427,7 @@ namespace Apache.NMS.ZMQ
 					nmsMessage.NMSType = messageNMSType;
 					if(null != messageProperties)
 					{
-						foreach(string propertyKey in messageProperties.Keys)
-						{
-							nmsMessage.Properties.SetBytes(propertyKey, messageProperties.GetBytes(propertyKey));
-						}
+						nmsMessage.PropertiesMap = PrimitiveMap.Unmarshal(messageProperties);
 					}
 				}
 				catch(InvalidOperationException)
@@ -428,7 +441,7 @@ namespace Apache.NMS.ZMQ
 
 					if(null != transformedMessage)
 					{
-						nmsMessage = transformedMessage;
+						nmsMessage = transformedMessage as BaseMessage;
 					}
 				}
 			}

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageProducer.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageProducer.cs?rev=1630251&r1=1630250&r2=1630251&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageProducer.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/MessageProducer.cs Wed Oct  8 23:17:41 2014
@@ -21,6 +21,7 @@ using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Net;
+using Apache.NMS.Util;
 
 namespace Apache.NMS.ZMQ
 {
@@ -135,17 +136,7 @@ namespace Apache.NMS.ZMQ
 			IPrimitiveMap properties = message.Properties;
 			if(null != properties && properties.Count > 0)
 			{
-				// Encode into a temporary buffer, and then place a single buffer into the msgDataBuilder.
-				List<byte> propertiesBuilder = new List<byte>();
-
-				EncodeFieldData(propertiesBuilder, propertiesBuilder.Count);
-				foreach(string propertyKey in properties.Keys)
-				{
-					EncodeFieldData(propertiesBuilder, propertyKey);
-					EncodeFieldData(propertiesBuilder, properties.GetBytes(propertyKey));
-				}
-
-				EncodeField(msgDataBuilder, WireFormat.MFT_HEADERS, propertiesBuilder.ToArray());
+				EncodeField(msgDataBuilder, WireFormat.MFT_HEADERS, ((PrimitiveMap) properties).Marshal());
 			}
 
 			if(message is ITextMessage)

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs?rev=1630251&r1=1630250&r2=1630251&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Session.cs Wed Oct  8 23:17:41 2014
@@ -169,6 +169,11 @@ namespace Apache.NMS.ZMQ
         public void DeleteDestination(IDestination destination)
         {
             // Nothing to delete.  Resources automatically disappear.
+			if(destination.IsTemporary)
+			{
+				destination.Dispose();
+			}
+
             return;
         }