activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgo...@apache.org
Subject svn commit: r777282 - /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs
Date Thu, 21 May 2009 22:05:55 GMT
Author: jgomes
Date: Thu May 21 22:05:55 2009
New Revision: 777282

URL: http://svn.apache.org/viewvc?rev=777282&view=rev
Log:
Restore TestMain.cs for documentation guide.

Added:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs
      - copied, changed from r682902, activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs

Copied: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs (from
r682902, activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs)
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs?p2=activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs&p1=activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs&r1=682902&r2=777282&rev=777282&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs Thu May
21 22:05:55 2009
@@ -14,64 +14,75 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-using Apache.NMS.ActiveMQ.Commands;
-using Apache.NMS;
+
 using System;
+using Apache.NMS;
+using Apache.NMS.Util;
 
 namespace Apache.NMS.ActiveMQ.Test
 {
-    public class TestMain
-    {
-        public static void Main(string[] args)
-        {
-            try
-            {
-                Console.WriteLine("About to connect to ActiveMQ");
-
-                // START SNIPPET: demo
-                IConnectionFactory factory = new ConnectionFactory(new Uri("tcp://localhost:61616"));
-                using (IConnection connection = factory.CreateConnection())
-                {
-                    Console.WriteLine("Created a connection!");
-                    
-                    ISession session = connection.CreateSession();
-                    
-                    IDestination destination = session.GetQueue("FOO.BAR");
-                    Console.WriteLine("Using destination: " + destination);
-                    
-                    // lets create a consumer and producer
-                    IMessageConsumer consumer = session.CreateConsumer(destination);
-                    
-                    IMessageProducer producer = session.CreateProducer(destination);
-                    producer.Persistent = true;
-                    
-                    // lets send a message
-                    ITextMessage request = session.CreateTextMessage("Hello World!");
-                    request.NMSCorrelationID = "abc";
-                    request.Properties["NMSXGroupID"] = "cheese";
-                    request.Properties["myHeader"] = "James";
-                    
-                    producer.Send(request);
-                    
-                    // lets consume a message
-                    ActiveMQTextMessage message = (ActiveMQTextMessage) consumer.Receive();
-                    if (message == null)
-                    {
-                        Console.WriteLine("No message received!");
-                    }
-                    else
-                    {
-                        Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
-                        Console.WriteLine("Received message with text: " + message.Text);
-                    }
-                }
-                // END SNIPPET: demo
-            }
-            catch (Exception e)
-            {
-                Console.WriteLine("Caught: " + e);
-                Console.WriteLine("Stack: " + e.StackTrace);
-            }
-        }
-    }
+	public class TestMain
+	{
+		public static void Main(string[] args)
+		{
+			try
+			{
+				// START SNIPPET: demo
+				Uri connecturi = new Uri("activemq:tcp://activemqhost:61616");
+				
+				Console.WriteLine("About to connect to " + connecturi);
+
+				// NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder.
+				IConnectionFactory factory = new NMSConnectionFactory(connecturi);
+
+				using(IConnection connection = factory.CreateConnection())
+				using(ISession session = connection.CreateSession())
+				{
+					/*
+					 * Examples for getting a destination:
+					 *   IDestination destination = session.GetQueue("FOO.BAR");  // Hard coded to queue
destination
+					 *   IDestination destination = session.GetTopic("FOO.BAR");  // Hard coded to topic
destination
+					 *   IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
 // Allows destination type to be embedded in name
+					 *   IDestination destination = SessionUtil.GetDestination(session, "topic://FOO.BAR");
 // Allows destination type to be embedded in name
+					 *   IDestination destination = SessionUtil.GetDestination(session, "FOO.BAR");    
     // Defaults to queue if type not specified.
+					 */
+					IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
+					Console.WriteLine("Using destination: " + destination);
+
+					// Create a consumer and producer
+					using(IMessageConsumer consumer = session.CreateConsumer(destination))
+					using(IMessageProducer producer = session.CreateProducer(destination))
+					{
+						producer.Persistent = true;
+
+						// Send a message
+						ITextMessage request = session.CreateTextMessage("Hello World!");
+						request.NMSCorrelationID = "abc";
+						request.Properties["NMSXGroupID"] = "cheese";
+						request.Properties["myHeader"] = "Cheddar";
+
+						producer.Send(request);
+
+						// Consume a message
+						ITextMessage message = consumer.Receive() as ITextMessage;
+						if(message == null)
+						{
+							Console.WriteLine("No message received!");
+						}
+						else
+						{
+							Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
+							Console.WriteLine("Received message with text: " + message.Text);
+						}
+					}
+				}
+				// END SNIPPET: demo
+			}
+			catch(Exception e)
+			{
+				Console.WriteLine("Caught: " + e);
+				Console.WriteLine("Stack: " + e.StackTrace);
+			}
+		}
+	}
 }



Mime
View raw message