activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r1145404 - in /activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk: ./ src/main/csharp/
Date Tue, 12 Jul 2011 00:28:55 GMT
Author: jgomes
Date: Tue Jul 12 00:28:55 2011
New Revision: 1145404

URL: http://svn.apache.org/viewvc?rev=1145404&view=rev
Log:
Implemented basic message producer.  Removed unnecessary ZmqMessage.  The normal message types
will be directly supported once the wire format encoding is added.
Fixes [AMQNET-333]. (See https://issues.apache.org/jira/browse/AMQNET-333)

Removed:
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/DefaultMessageConverter.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/IMessageConverter.cs
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/ZmqMessage.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Connection.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
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj
    activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x86.csproj

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Connection.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Connection.cs?rev=1145404&r1=1145403&r2=1145404&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Connection.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/src/main/csharp/Connection.cs Tue Jul 12
00:28:55 2011
@@ -27,8 +27,6 @@ namespace Apache.NMS.ZMQ
 	public class Connection : IConnection
 	{
 		private AcknowledgementMode acknowledgementMode = AcknowledgementMode.AutoAcknowledge;
-		private IMessageConverter messageConverter = new DefaultMessageConverter();
-
 		private IRedeliveryPolicy redeliveryPolicy;
 		private ConnectionMetaData metaData = null;
 		private bool closed = true;
@@ -45,7 +43,7 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		public void Start()
 		{
-			CheckConnected();
+			closed = false;
 		}
 
 		/// <summary>
@@ -54,7 +52,7 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		public bool IsStarted
 		{
-			get { return true; }
+			get { return !closed; }
 		}
 
 		/// <summary>
@@ -62,7 +60,7 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		public void Stop()
 		{
-			CheckConnected();
+			closed = true;
 		}
 
 		/// <summary>
@@ -78,13 +76,17 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		public ISession CreateSession(AcknowledgementMode mode)
 		{
-			CheckConnected();
 			return new Session(this, mode);
 		}
 
 		public void Dispose()
 		{
-			closed = true;
+			Close();
+		}
+
+		public void Close()
+		{
+			Stop();
 		}
 
 		/// <summary>
@@ -102,12 +104,6 @@ namespace Apache.NMS.ZMQ
 			set { acknowledgementMode = value; }
 		}
 
-		public IMessageConverter MessageConverter
-		{
-			get { return messageConverter; }
-			set { messageConverter = value; }
-		}
-
 		/// <summary>
 		/// Get/or set the broker Uri.
 		/// </summary>
@@ -123,10 +119,7 @@ namespace Apache.NMS.ZMQ
 		public string ClientId
 		{
 			get { return clientId; }
-			set
-			{
-				clientId = value;
-			}
+			set { clientId = value; }
 		}
 
 		/// <summary>
@@ -157,10 +150,7 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		static internal ZContext Context
 		{
-			get
-			{
-				return _context;
-			}
+			get { return _context; }
 		}
 
 		/// <summary>
@@ -188,20 +178,6 @@ namespace Apache.NMS.ZMQ
 		/// </summary>
 		public event ConnectionResumedListener ConnectionResumedListener;
 
-		protected void CheckConnected()
-		{
-			closed = false;
-			if(null == messageConverter)
-			{
-				throw new NMSException("Context Not Created");
-			}
-		}
-
-		public void Close()
-		{
-			Dispose();
-		}
-
 		public void HandleException(System.Exception e)
 		{
 			if(ExceptionListener != null && !this.closed)

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=1145404&r1=1145403&r2=1145404&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 Tue Jul
12 00:28:55 2011
@@ -19,9 +19,9 @@ using System;
 using System.Text;
 using System.Threading;
 using Apache.NMS.Util;
+using ZSendRecvOpt = ZMQ.SendRecvOpt;
 using ZSocket = ZMQ.Socket;
 using ZSocketType = ZMQ.SocketType;
-using ZSendRecvOpt = ZMQ.SendRecvOpt;
 
 namespace Apache.NMS.ZMQ
 {
@@ -114,16 +114,8 @@ namespace Apache.NMS.ZMQ
 		/// </returns>
 		public IMessage Receive()
 		{
-			IMessage nmsMessage = null;
-			if(null != messageSubscriber)
-			{
-				string messageText = messageSubscriber.Recv(Encoding.ASCII, ZSendRecvOpt.NOBLOCK);
-				if(!string.IsNullOrEmpty(messageText))
-				{
-					nmsMessage = ToNmsMessage(messageText);
-				}
-			}
-			return nmsMessage;
+			// TODO: Support decoding of all message types + all meta data (e.g., headers and properties)
+			return ToNmsMessage(messageSubscriber.Recv(Encoding.ASCII, ZSendRecvOpt.NOBLOCK));
 		}
 
 		/// <summary>
@@ -134,16 +126,8 @@ namespace Apache.NMS.ZMQ
 		/// </returns>
 		public IMessage Receive(TimeSpan timeout)
 		{
-			IMessage nmsMessage = null;
-			if(null != messageSubscriber)
-			{
-				string messageText = messageSubscriber.Recv(Encoding.ASCII, timeout.Milliseconds);
-				if(!string.IsNullOrEmpty(messageText))
-				{
-					nmsMessage = ToNmsMessage(messageText);
-				}
-			}
-			return nmsMessage;
+			// TODO: Support decoding of all message types + all meta data (e.g., headers and properties)
+			return ToNmsMessage(messageSubscriber.Recv(Encoding.ASCII, timeout.Milliseconds));
 		}
 
 		/// <summary>
@@ -257,60 +241,36 @@ namespace Apache.NMS.ZMQ
 		/// <returns>
 		/// nms message object
 		/// </returns>
-		protected virtual IMessage ToNmsMessage(ZmqMessage message)
+		protected virtual IMessage ToNmsMessage(string messageText)
 		{
-			IMessage ReturnValue = null;
-			if(null == message)
+			IMessage nmsMessage = new TextMessage(messageText);
+
+			try
 			{
-				return ReturnValue;
+				nmsMessage.NMSMessageId = "";
+				nmsMessage.NMSDestination = new Queue(contextBinding);
+				nmsMessage.NMSDeliveryMode = MsgDeliveryMode.NonPersistent;
+				nmsMessage.NMSPriority = MsgPriority.Normal;
+				nmsMessage.NMSTimestamp = DateTime.Now;
+				nmsMessage.NMSTimeToLive = new TimeSpan(0);
+				nmsMessage.NMSType = "";
+			}
+			catch(InvalidOperationException)
+			{
+				// Log error
 			}
 
-			ReturnValue = session.MessageConverter.ToNmsMessage(message);
-
-			if(this.ConsumerTransformer != null)
+			if(null != this.ConsumerTransformer)
 			{
-				IMessage newMessage = ConsumerTransformer(this.session, this, ReturnValue);
-				if(newMessage != null)
+				IMessage transformedMessage = ConsumerTransformer(this.session, this, nmsMessage);
+
+				if(null != transformedMessage)
 				{
-					ReturnValue = newMessage;
+					nmsMessage = transformedMessage;
 				}
 			}
-			return ReturnValue;
-		}
 
-		/// <summary>
-		/// Create nms message object
-		/// </summary>
-		/// <param name="message">
-		/// message text
-		/// </param>
-		/// <returns>
-		/// nms message object
-		/// </returns>
-		protected virtual IMessage ToNmsMessage(string messageText)
-		{
-			IMessage ReturnValue = null;
-			ZmqMessage message = ToZmqMessage(messageText);
-			ReturnValue = ToNmsMessage(message);
-			return ReturnValue;
-		}
-
-		/// <summary>
-		/// Create zmq message object 
-		/// </summary>
-		/// <param name="messageText">
-		/// message text
-		/// </param>
-		/// <returns>
-		/// zmq message object
-		/// </returns>
-		private ZmqMessage ToZmqMessage(string messageText)
-		{
-			ZmqMessage message = new ZmqMessage();
-			message.Destination = new Queue(this.contextBinding);
-			message.ClientId = session.Connection.ClientId;
-			message.Text = messageText;
-			return message;
+			return nmsMessage;
 		}
 	}
 }

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=1145404&r1=1145403&r2=1145404&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 Tue Jul
12 00:28:55 2011
@@ -84,7 +84,18 @@ namespace Apache.NMS.ZMQ
 
 		public void Send(IDestination destination, IMessage message, MsgDeliveryMode deliveryMode,
MsgPriority priority, TimeSpan timeToLive)
 		{
-			messageProducer.Send();
+			if(null != this.ProducerTransformer)
+			{
+				IMessage transformedMessage = ProducerTransformer(this.session, this, message);
+
+				if(null != transformedMessage)
+				{
+					message = transformedMessage;
+				}
+			}
+
+			// TODO: Support encoding of all message types + all meta data (e.g., headers and properties)
+			messageProducer.Send(((ITextMessage) message).Text, Encoding.ASCII);
 		}
 
 		public void Dispose()

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=1145404&r1=1145403&r2=1145404&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 Tue Jul 12 00:28:55
2011
@@ -28,13 +28,11 @@ namespace Apache.NMS.ZMQ
 		private Connection connection;
 		private AcknowledgementMode acknowledgementMode;
 		private MessageQueueTransaction messageQueueTransaction;
-		private IMessageConverter messageConverter;
 
 		public Session(Connection connection, AcknowledgementMode acknowledgementMode)
 		{
 			this.connection = connection;
 			this.acknowledgementMode = acknowledgementMode;
-			MessageConverter = connection.MessageConverter;
 			if(this.acknowledgementMode == AcknowledgementMode.Transactional)
 			{
 				MessageQueueTransaction = new MessageQueueTransaction();
@@ -43,9 +41,15 @@ namespace Apache.NMS.ZMQ
 
 		public void Dispose()
 		{
+			Close();
+		}
+
+		public void Close()
+		{
 			if(MessageQueueTransaction != null)
 			{
 				MessageQueueTransaction.Dispose();
+				MessageQueueTransaction = null;
 			}
 		}
 
@@ -229,12 +233,6 @@ namespace Apache.NMS.ZMQ
 			set { messageQueueTransaction = value; }
 		}
 
-		public IMessageConverter MessageConverter
-		{
-			get { return messageConverter; }
-			set { messageConverter = value; }
-		}
-
 		private ConsumerTransformerDelegate consumerTransformer;
 		public ConsumerTransformerDelegate ConsumerTransformer
 		{
@@ -248,10 +246,5 @@ namespace Apache.NMS.ZMQ
 			get { return this.producerTransformer; }
 			set { this.producerTransformer = value; }
 		}
-
-		public void Close()
-		{
-			Dispose();
-		}
 	}
 }

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj?rev=1145404&r1=1145403&r2=1145404&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x64.csproj Tue Jul 12
00:28:55 2011
@@ -57,9 +57,7 @@
     <Compile Include="src\main\csharp\TemporaryTopic.cs" />
     <Compile Include="src\main\csharp\Topic.cs" />
     <Compile Include="src\main\csharp\TemporaryQueue.cs" />
-    <Compile Include="src\main\csharp\DefaultMessageConverter.cs" />
     <Compile Include="src\main\csharp\Destination.cs" />
-    <Compile Include="src\main\csharp\IMessageConverter.cs" />
     <Compile Include="src\main\csharp\MapMessage.cs" />
     <Compile Include="src\main\csharp\MessageConsumer.cs" />
     <Compile Include="src\main\csharp\MessageProducer.cs" />
@@ -70,7 +68,6 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\main\csharp\TextMessage.cs" />
-    <Compile Include="src\main\csharp\ZmqMessage.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="lib\clrzmq\net-4.0\libzmq64.dll">

Modified: activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x86.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x86.csproj?rev=1145404&r1=1145403&r2=1145404&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x86.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS.ZMQ/trunk/vs2010-zmq-net-4.0x86.csproj Tue Jul 12
00:28:55 2011
@@ -57,9 +57,7 @@
     <Compile Include="src\main\csharp\TemporaryTopic.cs" />
     <Compile Include="src\main\csharp\Topic.cs" />
     <Compile Include="src\main\csharp\TemporaryQueue.cs" />
-    <Compile Include="src\main\csharp\DefaultMessageConverter.cs" />
     <Compile Include="src\main\csharp\Destination.cs" />
-    <Compile Include="src\main\csharp\IMessageConverter.cs" />
     <Compile Include="src\main\csharp\MapMessage.cs" />
     <Compile Include="src\main\csharp\MessageConsumer.cs" />
     <Compile Include="src\main\csharp\MessageProducer.cs" />
@@ -70,7 +68,6 @@
       <SubType>Code</SubType>
     </Compile>
     <Compile Include="src\main\csharp\TextMessage.cs" />
-    <Compile Include="src\main\csharp\ZmqMessage.cs" />
   </ItemGroup>
   <ItemGroup>
     <Content Include="lib\clrzmq\net-4.0\libzmq.dll">



Mime
View raw message