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 2009/05/22 19:13:01 UTC

svn commit: r777622 - in /activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp: TestMain.cs TestMainAsync.cs

Author: jgomes
Date: Fri May 22 17:13:00 2009
New Revision: 777622

URL: http://svn.apache.org/viewvc?rev=777622&view=rev
Log:
Fix sample code files to not compile into main product.  Added additional comments for clarification of intent.

Modified:
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMain.cs
    activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMainAsync.cs

Modified: 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?rev=777622&r1=777621&r2=777622&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 Fri May 22 17:13:00 2009
@@ -18,6 +18,7 @@
 // NOTE: Keep leading spaces.  Do not convert to tabs.  This file
 // is auto-linked on the NMS website as example code.
 
+#if false	// This file should not be compiled into the product.  Demo only.
 // START SNIPPET: demo
 using System;
 using Apache.NMS;
@@ -25,67 +26,71 @@
 
 namespace Apache.NMS.ActiveMQ.Test
 {
-    public class TestMain
+public class TestMain
+{
+    public static void Main(string[] args)
     {
-        public static void Main(string[] args)
+        // Example connection strings:
+        //    activemq:tcp://activemqhost:61616
+        //    activemq:tcp://activemqhost:61613?transport.wireformat=stomp
+        //    ems:tcp://tibcohost:7222
+        //    msmq://localhost
+
+        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())
         {
-            try
+             // Examples for getting a destination:
+             //
+             // Hard coded destinations:
+             //    IDestination destination = session.GetQueue("FOO.BAR");
+             //    IDestination destination = session.GetTopic("FOO.BAR");
+             //
+             // Embedded destination type in the name:
+             //    IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
+             //    IDestination destination = SessionUtil.GetDestination(session, "topic://FOO.BAR");
+             //
+             // Defaults to queue if type is not specified:
+             //    IDestination destination = SessionUtil.GetDestination(session, "FOO.BAR");
+
+            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))
             {
-                Uri connecturi = new Uri("activemq:tcp://activemqhost:61616");
-                
-                Console.WriteLine("About to connect to " + connecturi);
+                producer.Persistent = true;
 
-                // 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())
+                // 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)
                 {
-                    /*
-                     * 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);
-                        }
-                    }
+                    Console.WriteLine("No message received!");
+                }
+                else
+                {
+                    Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
+                    Console.WriteLine("Received message with text: " + message.Text);
                 }
-            }
-            catch(Exception e)
-            {
-                Console.WriteLine("Caught: " + e);
-                Console.WriteLine("Stack: " + e.StackTrace);
             }
         }
     }
 }
+}
 // END SNIPPET: demo
+#endif

Modified: activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMainAsync.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMainAsync.cs?rev=777622&r1=777621&r2=777622&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMainAsync.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS.ActiveMQ/trunk/src/test/csharp/TestMainAsync.cs Fri May 22 17:13:00 2009
@@ -18,6 +18,7 @@
 // NOTE: Keep leading spaces.  Do not convert to tabs.  This file
 // is auto-linked on the NMS website as example code.
 
+#if false	// This file should not be compiled into the product.  Demo only.
 // START SNIPPET: demo
 using System;
 using System.Threading;
@@ -26,80 +27,84 @@
 
 namespace Apache.NMS.ActiveMQ.Test
 {
-    public class TestMain
+public class TestMain
+{
+    protected static AutoResetEvent semaphore = new AutoResetEvent(false);
+    protected static ITextMessage message = null;
+    protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);
+    
+    public static void Main(string[] args)
     {
-        protected static AutoResetEvent semaphore = new AutoResetEvent(false);
-        protected static ITextMessage message = null;
-        protected static TimeSpan receiveTimeout = TimeSpan.FromSeconds(10);
+        // Example connection strings:
+        //    activemq:tcp://activemqhost:61616
+        //    activemq:tcp://activemqhost:61613?transport.wireformat=stomp
+        //    ems:tcp://tibcohost:7222
+        //    msmq://localhost
+
+        Uri connecturi = new Uri("activemq:tcp://activemqhost:61616");
         
-        public static void Main(string[] args)
-        {
-            try
-            {
-                Uri connecturi = new Uri("activemq:tcp://activemqhost:61616");
-                
-                Console.WriteLine("About to connect to " + connecturi);
+        Console.WriteLine("About to connect to " + connecturi);
 
-                // NOTE: ensure the nmsprovider-activemq.config file exists in the executable folder.
-                IConnectionFactory factory = new NMSConnectionFactory(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())
+        using(IConnection connection = factory.CreateConnection())
+        using(ISession session = connection.CreateSession())
+        {
+             // Examples for getting a destination:
+             //
+             // Hard coded destinations:
+             //    IDestination destination = session.GetQueue("FOO.BAR");
+             //    IDestination destination = session.GetTopic("FOO.BAR");
+             //
+             // Embedded destination type in the name:
+             //    IDestination destination = SessionUtil.GetDestination(session, "queue://FOO.BAR");
+             //    IDestination destination = SessionUtil.GetDestination(session, "topic://FOO.BAR");
+             //
+             // Defaults to queue if type is not specified:
+             //    IDestination destination = SessionUtil.GetDestination(session, "FOO.BAR");
+
+            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))
+            {
+                connection.Start();     // Must start the connection for async messaging.
+                producer.Persistent = true;
+                producer.RequestTimeout = receiveTimeout;
+                consumer.Listener += new MessageListener(OnMessage);
+
+                // Send a message
+                ITextMessage request = session.CreateTextMessage("Hello World!");
+                request.NMSCorrelationID = "abc";
+                request.Properties["NMSXGroupID"] = "cheese";
+                request.Properties["myHeader"] = "Cheddar";
+
+                producer.Send(request);
+
+                // Wait for the message
+                semaphore.WaitOne((int) receiveTimeout.TotalMilliseconds, true);
+                if(message == null)
                 {
-                    /*
-                     * 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))
-                    {
-                        connection.Start();     // Must start the connection for async messaging.
-                        producer.Persistent = true;
-                        producer.RequestTimeout = receiveTimeout;
-                        consumer.Listener += new MessageListener(OnMessage);
-
-                        // Send a message
-                        ITextMessage request = session.CreateTextMessage("Hello World!");
-                        request.NMSCorrelationID = "abc";
-                        request.Properties["NMSXGroupID"] = "cheese";
-                        request.Properties["myHeader"] = "Cheddar";
-
-                        producer.Send(request);
-
-                        // Wait for the message
-                        semaphore.WaitOne((int) receiveTimeout.TotalMilliseconds, true);
-                        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);
-                        }
-                    }
+                    Console.WriteLine("No message received!");
+                }
+                else
+                {
+                    Console.WriteLine("Received message with ID:   " + message.NMSMessageId);
+                    Console.WriteLine("Received message with text: " + message.Text);
                 }
-            }
-            catch(Exception e)
-            {
-                Console.WriteLine("Caught: " + e);
-                Console.WriteLine("Stack: " + e.StackTrace);
             }
         }
+    }
 
-        protected static void OnMessage(IMessage receivedMsg)
-        {
-            message = receivedMsg as ITextMessage;
-            semaphore.Set();
-        }
+    protected static void OnMessage(IMessage receivedMsg)
+    {
+        message = receivedMsg as ITextMessage;
+        semaphore.Set();
     }
 }
+}
 // END SNIPPET: demo
+#endif