activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject [08/18] Porting apollo examples structure to ActiveMQ 5.9.
Date Thu, 10 Oct 2013 14:40:31 GMT
http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/DurableChat/DurableChat.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/DurableChat/DurableChat.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/DurableChat/DurableChat.java
new file mode 100644
index 0000000..5bcdc8b
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/DurableChat/DurableChat.java
@@ -0,0 +1,268 @@
+/*
+Copyright 2001-2008, Progress Software Corporation -  All Rights Reserved
+
+DurableChat application
+
+A basic JMS Application that uses:
+    - Publish and Subscribe
+    - Durable Subsciptions
+    - Persistent Messages
+
+This sample publishes and subscribes to a specified topic.
+Text you enter is published to the topic with the user name.
+The message will persist for ten minutes if the subscriber is not available.
+If the subscriber reconnects within that time, the message is delivered.
+
+Usage:
+  java DurableChat -b <broker:port> -u <username> -p <password>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+
+Suggested demonstration:
+  - In separate console windows, start instances of the application
+    under unique user names.For example:
+       java DurableChat -b tcp://localhost:61616 -u ACCOUNTING
+       java DurableChat -b tcp://localhost:61616 -u LEGAL
+  - Enter text and then press Enter to publish the message.
+  - See messages appear under the various user names as you
+    enter messages in each console window.
+  - Stop a session by pressing CTRL+C in its console window.
+  - Keep sending messages in other sessions.
+  - Restart the subscriber username session that was stopped.
+  - Note that the "missed" messages are still available if the restart is
+    within thirty minutes.
+
+*/
+import org.apache.activemq.*;
+
+
+public class DurableChat implements
+     javax.jms.MessageListener      // to handle message subscriptions
+{
+    private static final String APP_TOPIC = "jms.samples.durablechat";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final long   MESSAGE_LIFESPAN = 1800000; //30 minutes
+
+    private javax.jms.Connection connection = null;
+    private javax.jms.Session pubSession = null;
+    private javax.jms.Session subSession = null;
+
+
+    public void DurableChatter(String broker, String username, String password)
+    {
+        javax.jms.MessageProducer publisher = null;
+        javax.jms.MessageConsumer subscriber = null;
+        javax.jms.Topic topic = null;
+
+        //Create a connection:
+        try{
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connection = factory.createConnection (username, password);
+
+            //Durable Subscriptions are indexed by username, clientID and subscription name
+            //It is a good practice to set the clientID:
+            connection.setClientID(username);
+            pubSession = connection.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            subSession = connection.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse){
+            System.err.println ("Error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        //Create Publisher and Durable Subscriber:
+        try{
+
+            topic = pubSession.createTopic(APP_TOPIC);
+            subscriber = subSession.createDurableSubscriber(topic, username);
+            subscriber.setMessageListener(this);
+            publisher = pubSession.createProducer(topic);
+            connection.start();
+        }
+        catch (javax.jms.JMSException jmse){
+            System.out.println("Error: connection not started.");
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        //Wait for user input
+        try
+        {
+            System.out.println("\nDurableChat application:\n"
+            					+ "========================\n"
+            					+ "The user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+								+ "The application will publish messages to the " + APP_TOPIC + " topic.\n"
+                                + "The application also creates a durable subscription to that topic to consume any messages published there.\n\n"
+                                + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n");
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
+            while (true)
+            {
+                String s = stdin.readLine();
+
+                if(s == null){
+                    exit();
+                }
+                else if (s.length()>0)
+                {
+                    try
+                    {
+                        javax.jms.TextMessage msg = pubSession.createTextMessage();
+                        msg.setText(username + ": " + s);
+                        //Publish the message persistantly:
+                        publisher.send(
+                            msg,                               //message
+                            javax.jms.DeliveryMode.PERSISTENT, //publish persistently
+                            javax.jms.Message.DEFAULT_PRIORITY,//priority
+                            MESSAGE_LIFESPAN);                 //Time to Live
+                    }
+                    catch (javax.jms.JMSException jmse){
+                        System.err.println("Error publishing message:" + jmse.getMessage());
+                    }
+                }
+            }
+        }
+        catch (java.io.IOException ioe)
+        {
+            ioe.printStackTrace();
+        }
+    }
+
+    /** Message Handler**/
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            connection.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = null;
+        String password  = DEFAULT_PASSWORD;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+        }
+
+        // Start the JMS client for the "chat".
+        DurableChat durableChat = new DurableChat();
+        durableChat.DurableChatter (broker, username, password);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java DurableChat (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u username  Specify unique user name. (Required)\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/HierarchicalChat/HierarchicalChat.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/HierarchicalChat/HierarchicalChat.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/HierarchicalChat/HierarchicalChat.java
new file mode 100644
index 0000000..997e3b5
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/HierarchicalChat/HierarchicalChat.java
@@ -0,0 +1,303 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+Sample Application
+
+Writing a JMS Application using Publish and Subscribe with
+Hierarchical Topics
+
+This sample publishes and subscribes to specified topic nodes.
+Text you enter is published and then received by all subscribers to
+the that topic on the specified broker.
+
+Usage:
+  java HierarchicalChat -b <broker:port> -u <username> -p <password> -t <pubTopicname> -s <subTopicname>
+      -b broker:port        points to a message broker
+                            Default: tcp://localhost:61616
+      -u username           must be unique (but is not checked)
+      -p password           password for user (not checked)
+      -t pubTopicname     	name of topic to which to publish
+                            Default: jms.samples.hierarchicalchat
+      -s subTopicname	    name of topic to which to subscribe
+                            Default: jms.samples.*
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application
+    under unique user names.
+    For example:
+       java HierarchicalChat -u SALES -t sales -s sales.*
+       java HierarchicalChat -u USA -t sales.usa -s sales.usa
+  - Enter text in the USA console window and then press Enter
+    to publish the message.
+  - Note that messages published from the SALES console window
+    to the sales topic are not seen by the USA user listening
+    to messages on the sales.usa topic
+  - Message published to the sales.usa are received by the SALES
+    user listening to sales.*
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+
+import org.apache.activemq.*;
+
+
+public class HierarchicalChat
+    implements javax.jms.MessageListener
+{
+    private static final String DEFAULT_PUBLISHER_TOPIC = "jms.samples.hierarchicalchat";
+    private static final String DEFAULT_SUBSCRIBER_TOPIC = "jms.samples.*";
+    private static final String DEFAULT_SUBSCRIBER_ROOT = "jms.samples";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+
+    private static final String DEFAULT_PASSWORD = "password";
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session pubSession = null;
+    private javax.jms.Session subSession = null;
+    private javax.jms.MessageProducer publisher = null;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void chatter( String broker, String username, String password, String pubTopicname, String subTopicname)
+    {
+
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            pubSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            subSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Publisher and Subscriber to 'chat' topics
+        // Note that the publish and subscribe topics are different.
+        try
+        {
+            javax.jms.Topic subscriberTopic = pubSession.createTopic (subTopicname);
+            javax.jms.MessageConsumer subscriber = subSession.createConsumer(subscriberTopic, null, false);
+            subscriber.setMessageListener(this);
+            javax.jms.Topic publisherTopic = pubSession.createTopic (pubTopicname);
+            publisher = pubSession.createProducer(publisherTopic);
+            // Now that setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+        try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+                        System.out.println("\nHierarchicalChat application:\n"
+			            					+ "============================\n"
+			            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+											+ "The application will publish messages to the " + DEFAULT_PUBLISHER_TOPIC + " topic." + ".\n"
+			                                + "The application also subscribes to topics using the wildcard syntax " + DEFAULT_SUBSCRIBER_TOPIC 
+											+ " so that it can receive all messages to " + DEFAULT_SUBSCRIBER_ROOT + " and its subtopics.\n\n"
+			                                + "Type some text, and then press Enter to publish a TextMesssage from " + username + ".\n");
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 )
+                {
+                    javax.jms.TextMessage msg = pubSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    publisher.send( msg );
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = null;
+        String password  = DEFAULT_PASSWORD;
+        String pubTopicname = DEFAULT_PUBLISHER_TOPIC;
+        String subTopicname = DEFAULT_SUBSCRIBER_TOPIC;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+            // Options
+            if (!arg.startsWith("-")) {
+                System.err.println ("error: unexpected argument - "+arg);
+                printUsage();
+                System.exit(1);
+            }
+            else {
+                if (arg.equals("-b")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing broker name:port");
+                        System.exit(1);
+                    }
+                    broker = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-u")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing user name");
+                        System.exit(1);
+                    }
+                    username = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-p")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing password");
+                        System.exit(1);
+                    }
+                    password = argv[++i];
+                    continue;
+                }
+                if (arg.equals("-t")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing publisher topic name");
+                        System.exit(1);
+                    }
+                    pubTopicname = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-s")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing subscriber topic name");
+                        System.exit(1);
+                    }
+                    subTopicname = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-h")) {
+                    printUsage();
+                    System.exit(1);
+                }
+            }
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+        }
+
+        // Start the JMS client for the "chat".
+        HierarchicalChat chat = new HierarchicalChat();
+        chat.chatter (broker, username, password, pubTopicname, subTopicname);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java HierarchicalChat (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port          Specify name:port of broker.\n");
+        use.append("                        Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name               Specify unique user name. (Required)\n");
+        use.append("  -p password           Specify password for user.\n");
+        use.append("                        Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -t pubTopicname       name of topic to which to publish.\n");
+        use.append("                        Default publisher topic name: "+DEFAULT_PUBLISHER_TOPIC+"\n");
+        use.append("  -s subTopicname       Specify subscriber topic name.\n");
+        use.append("                        name of topic to which to subscribe: "+DEFAULT_SUBSCRIBER_TOPIC+"\n");
+        use.append("  -h                    This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.java
new file mode 100644
index 0000000..19ab78f
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.java
@@ -0,0 +1,328 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+Sample Application
+
+Writing a Basic JMS Application Using
+    Subscribe
+
+When you run this program, it will
+subscribe to any group of messages specified
+in a properties file. [See comments in
+MessageMonitor.properties for information on
+this file.]
+
+Every message topic being monitored will be
+displayed to a Java window.
+
+Usage:
+  java MessageMonitor
+
+Suggested demonstration:
+  - Start one instance of this application:
+        java MessageMonitor
+  - Run one or more Chat and/or DurableChat window(s).
+  - Enter messages on the various chat windows.
+  - Watch the MessageMonitor display the messages.
+*/
+import org.apache.activemq.*;
+
+import javax.swing.JTextArea;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+import javax.swing.JButton;
+
+import javax.swing.text.Highlighter;
+import javax.swing.text.DefaultHighlighter;
+import javax.swing.text.BadLocationException;
+
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.BevelBorder;
+import javax.swing.border.SoftBevelBorder;
+
+import java.awt.Toolkit;
+import java.awt.Dimension;
+import java.awt.BorderLayout;
+import java.awt.Rectangle;
+
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+
+import javax.jms.Topic;
+import javax.jms.Session;
+import javax.jms.Connection;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+
+
+import java.io.FileInputStream;
+
+import java.util.Vector;
+import java.util.Properties;
+import java.util.StringTokenizer;
+
+public class MessageMonitor
+extends JFrame
+{
+    private static final String DEFAULT_PROPERTIES_FILE = "MessageMonitor.properties";
+
+    String propertiesFile = DEFAULT_PROPERTIES_FILE;
+    String brokerHostPort = "localhost";
+    String connectID = "MessageMonitor";
+    String userID = "Administrator";
+    
+    String subscriptionTopics = "jms.samples.chat";
+    String textFontName = "Dialog";
+    String textFontStyle = "PLAIN";
+    String textFontSize = "12";
+    String title = "MessageMonitor";
+
+    JTextArea textArea = new JTextArea();
+    JScrollPane scrollPane = new JScrollPane(textArea);
+    JButton clearButton = new JButton("Clear");
+
+    Connection connection = null;
+    Session session = null;
+
+    private String user = ActiveMQConnection.DEFAULT_USER;
+    private String password = ActiveMQConnection.DEFAULT_PASSWORD;
+    private String url = ActiveMQConnection.DEFAULT_BROKER_URL;
+
+
+    /** Constructor for MessageMonitor window. */
+    public MessageMonitor()
+    {
+        loadProperties();
+
+        setTitle(title);
+
+        // Connect to Message Broker
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(user, password, url);
+
+            connection = factory.createConnection (userID, password);
+            session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("Cannot connect to Broker");
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Subscribe to Topics
+        StringTokenizer topics = new StringTokenizer(subscriptionTopics, ",");
+        while (topics.hasMoreTokens())
+        {
+            try
+            {
+                String topicName = topics.nextToken();
+                System.out.println ("Subscribing to: " + topicName);
+                new Subscription(session.createTopic(topicName));
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+
+        // Set up the viewing area.
+        textArea.setEditable(false);
+        scrollPane.setBorder(new CompoundBorder(new EmptyBorder(6,6,6,6),
+                                                new SoftBevelBorder(BevelBorder.LOWERED)));
+        getContentPane().add(scrollPane,BorderLayout.CENTER);
+        getContentPane().add(clearButton,BorderLayout.SOUTH);
+        clearButton.addActionListener(new OnClear());
+        // Start the connection so that we can now receive messages.
+        try
+        {
+            connection.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("Cannot start connection");
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+    }
+
+    /** Class to handle the subsciption to messages. */
+    public class Subscription implements javax.jms.MessageListener
+    {
+        public Subscription(Topic topic)
+        {
+            try
+            {
+                topicSubscriber = session.createConsumer(topic);
+                topicSubscriber.setMessageListener(this);
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+
+       /**
+        * Handle the text message
+        * (as specified in the javax.jms.MessageListener interface).
+        */
+
+        public void onMessage(javax.jms.Message message)
+        {
+            String msgBody = null;
+            String msgClass = null;
+
+            if (message instanceof javax.jms.TextMessage)
+            {
+                msgClass = "javax.jms.TextMessage";
+                try
+                {
+                    msgBody = ((javax.jms.TextMessage)message).getText();
+                }
+                catch (javax.jms.JMSException jmse)
+                {
+                    msgBody = "";
+                }
+            }
+            else
+            {
+                return;
+            }
+            try
+            {
+                textArea.append("\n");
+                textArea.append("-----------------------------------------------------------------------------------------------------\n");
+                // textArea.append("Class: " + msgClass + "\n");
+                textArea.append("The following message, received on topic " + ((Topic)message.getJMSDestination()).getTopicName() + ", was sent by\n");
+                //textArea.append("\n");
+                textArea.append(msgBody);
+
+                // Ensure Appended Text is Visible
+                Rectangle area = textArea.modelToView(textArea.getText().length());
+                if (area != null) textArea.scrollRectToVisible(area);
+
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+            catch (BadLocationException ble)
+            {
+                ble.printStackTrace();
+            }
+
+        }
+
+        MessageConsumer topicSubscriber = null;
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String[] args)
+    {
+        // There should be no arguments to this program.
+        if (args.length > 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        MessageMonitor messageMonitor = new MessageMonitor();
+
+        messageMonitor.addWindowListener(new WindowAdapter() {
+            public void windowClosing(WindowEvent e)
+            {
+                System.exit(0);
+            }
+        });
+
+        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+        screenSize.height = screenSize.height / 2 ;
+        screenSize.width = screenSize.width / 2 ;
+        messageMonitor.setSize(screenSize);
+        messageMonitor.setVisible(true);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage()
+    {
+        StringBuffer use = new StringBuffer();
+        use.append("\nusage: MessageMonitor\n\n");
+        use.append("Properties for this sample can be set in a properties file.\n");
+        String dfltFile = System.getProperty("propertiesFile", DEFAULT_PROPERTIES_FILE);
+        use.append("[Default file: " + dfltFile +"]\n\n");
+
+        System.out.print(use);
+    }
+
+    /** Load the window and JMS properties from a file. */
+    private void loadProperties()
+    {
+        try
+        {
+            Properties properties = new Properties();
+
+            propertiesFile = System.getProperty("propertiesFile", propertiesFile);
+
+            properties.load(new FileInputStream(propertiesFile));
+
+            // Connection Properties
+            brokerHostPort = properties.getProperty("brokerHostPort",brokerHostPort).trim();
+            connectID = properties.getProperty("connectID",connectID).trim();
+            userID = properties.getProperty("userID",userID).trim();
+            password = properties.getProperty("password",password).trim();
+
+            // Subscription Properties
+            subscriptionTopics = properties.getProperty("subscriptionTopics", subscriptionTopics).trim();
+
+            // Text Properties
+            textFontName = properties.getProperty("textFontName", textFontName).trim();
+            textFontStyle = properties.getProperty("textFontSize", textFontStyle).trim();
+            textFontSize = properties.getProperty("textFontSize", textFontSize).trim();
+
+            // Window Properties
+            title = properties.getProperty("title", title).trim();
+
+        }
+        catch (java.io.FileNotFoundException fnfe)
+        {
+            System.out.println (propertiesFile + " not found: using defaults"); // Use Defaults
+        }
+        catch (java.io.IOException ioe)
+        {
+            ioe.printStackTrace();
+        }
+    }
+
+    /** Class to handle the "Clear" button action. */
+    public class OnClear implements ActionListener
+    {
+        public void actionPerformed(ActionEvent evt)
+        {
+            textArea.setText("");
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.properties
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.properties b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.properties
new file mode 100644
index 0000000..b272abe
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/MessageMonitor/MessageMonitor.properties
@@ -0,0 +1,55 @@
+#
+# This is the properties file for the MessageMonitor Class.
+#
+# A MessageMonitor object will load this file when constructed.
+# By default, a MessageMonitor object searches for and load a 
+# file named "MessageMonitor.properties" in the JVM's "current" directory.
+#
+# This behavior may be overriden by assigning an alternate property file
+# name and location to the System property "propertiesFile".
+#
+# Property:         brokerHostPort
+# Default Value:    localhost   
+# Description:      Specifies the host and port of the Messaging Broker to connect to.
+brokerHostPort      localhost  
+#
+# Property:         connectID
+# Default Value:    MessageMonitor
+# Description:      Specifies the program identifier used to connect to the Messaging Broker.
+connectID MessageMonitor   
+#
+# Property:         userID
+# Default Value:    MessageMonitor
+# Description:      Specifies the user identifier used to connect to the Messaging Broker.
+userID              Administrator   
+#
+# Property:         password
+# Default Value:    MessageMonitor
+# Description:      Specifies the password used to connect to the Messaging Broker.
+password            Administrator   
+#
+# Property:         subscriptionTopics
+# Default Value:    jms.samples.#
+# Description:      A comma-separated list of topics that MessageMonitor subscribes to.
+#                   An empty list will subscribe to jms.samples.#.
+subscriptionTopics  jms.samples.*
+##
+# Property:         textFontName
+# Default Value:    Dialog
+# Description:      The name of the font used to display recieved messages.
+textFontName        Dialog   
+#
+# Property:         textFontStyle
+# Default Value:    PLAIN
+# Description:      The style of the font used to display recieved messages.
+textFontStyle       PLAIN   
+#
+# Property:         textFontSize
+# Default Value:    12
+# Description:      The size of the font used to display recieved messages.
+textFontSize        12   
+#
+# Property:         title
+# Default Value:    MessageMonitor
+# Description:      The title of the MessageMonitor Window.
+title               MessageMonitor   

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicReplier.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicReplier.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicReplier.java
new file mode 100644
index 0000000..a786afe
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicReplier.java
@@ -0,0 +1,318 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+Sample Application
+
+Writing a Basic JMS Application using:
+    - Synchronous Request/Reply
+    - Publish/Subscribe
+    - javax.jms.TopicRequestor class
+    - JMSReplyTo Header
+
+When this program runs, it waits for
+messages to the topic "jms.samples.request".
+When that message occurs, a response based on the request
+is sent back to the "Requestor" specified in the JMSReplyTo header.
+
+This sample replies with a simple text manipulation of the request;
+the text is either folded to all UPPERCASE or all lowercase.
+
+Usage:
+  java TopicReplier -b <broker:port> -u <username> -p <password> -m <mode>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+                     Default: SampleReplier
+      -p password    password for user (not checked)
+                     Default: password
+      -m mode        replier mode (uppercase, or lowercase)
+                     Default: uppercase
+
+Suggested usage:
+  - In a console window with the environment set, start a replier:
+       java TopicReplier -u SampleReplier
+  - In another console window, start a Requestor:
+       java TopicRequestor -u SampleRequestor
+  - Enter text in the Requestor window then press Enter.
+
+    The Replier responds with the message in all uppercase characters.
+  - Start other TopicRequestors with different user names to see that
+    replies are not broadcast to all users. For example:
+       java TopicRequestor -u SampleRequestorToo
+
+  - Start other TopicRepliers.
+  - See that all repliers are receiving all the messages,(as they should).
+  - See the Requestor only receives one response.
+       java TopicReplier -u toLower -m lowercase
+
+ */
+
+import org.apache.activemq.*;
+
+
+public class TopicReplier
+    implements javax.jms.MessageListener
+{
+    private static final String APP_TOPIC = "jms.samples.request";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_USER_NAME = "SampleReplier";
+    private static final String DEFAULT_PASSWORD = "password";
+    private static final String DEFAULT_MODE = "uppercase";
+    private static final int UPPERCASE = 0;
+    private static final int LOWERCASE = 1;
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session session = null;
+    private javax.jms.MessageProducer replier = null;
+
+    private int imode = UPPERCASE;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void start ( String broker, String username, String password, String mode)
+    {
+        // Set the operation mode
+        imode = (mode.equals("uppercase")) ? UPPERCASE : LOWERCASE;
+
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            session = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Subscriber to application topics as well as a Publisher
+        // to use for JMS replies.
+        try
+        {
+            javax.jms.Topic topic = session.createTopic (APP_TOPIC);
+            javax.jms.MessageConsumer subscriber = session.createConsumer(topic);
+            subscriber.setMessageListener(this);
+            replier = session.createProducer(null);  // Topic will be set for each reply
+            // Now that all setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            while ( true )
+            {
+                  System.out.println ("\nReplier application:\n"
+			            					+ "============================\n"
+			            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+											+ "The application gets requests with JMSReplyTo set on the " + APP_TOPIC + " topic."
+											+ "The message is transformed to all uppercase or all lowercase, and then returned to the requestor."
+			                                + "The Requestor application displays the result.\n\n"
+			                                + "Enter EXIT or press Ctrl+C to close the Replier.\n");
+                String s = stdin.readLine();
+                if ( s == null || s.equalsIgnoreCase("EXIT"))
+                {
+                    System.out.println ("\nStopping Replier. Please wait..\n>");
+                    exit();
+                }
+           }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message.
+     * (as specified in the javax.jms.MessageListener interface).
+     *
+     * IMPORTANT NOTE: We must follow the design paradigm for JMS
+     * synchronous requests.  That is, we must:
+     *   - get the message
+     *   - look for the header specifying JMSReplyTo
+     *   - send a reply to the topic specified there.
+     * Failing to follow these steps might leave the originator
+     * of the request waiting forever.
+     *
+     * OPTIONAL BEHAVIOR: The following actions taken by the
+     * message handler represent good programming style, but are
+     * not required by the design paradigm for JMS requests.
+     *   - set the JMSCorrelationID (tying the response back to
+     *     the original request.
+     *   - use transacted session "commit" so receipt of request
+     *     won't happen without the reply being sent.
+     *
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( "[Request] " + string );
+
+                // Check for a ReplyTo topic
+                javax.jms.Topic replyTopic = (javax.jms.Topic) aMessage.getJMSReplyTo();
+                if (replyTopic != null)
+                {
+                    // Send the modified message back.
+                    javax.jms.TextMessage reply =  session.createTextMessage();
+                    if (imode == UPPERCASE)
+                        reply.setText("Transformed " + string + " to all uppercase: " + string.toUpperCase());
+                    else
+                        reply.setText("Transformed " + string + " to all lowercase " + string.toLowerCase());
+                    reply.setJMSCorrelationID(aMessage.getJMSMessageID());
+                    replier.send(replyTopic, reply);
+                    session.commit();
+                }
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = DEFAULT_USER_NAME;
+        String password  = DEFAULT_PASSWORD;
+        String mode  = DEFAULT_MODE;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-m")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing mode");
+                    System.exit(1);
+                }
+                mode = argv[++i];
+                if (!(mode.equals("uppercase") || mode.equals("lowercase"))) {
+                    System.err.println("error: mode must be 'uppercase' or 'lowercase'");
+                    System.exit(1);
+                }
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+
+        // Start the JMS client for the "chat".
+        TopicReplier replier = new TopicReplier();
+        replier.start (broker, username, password, mode);
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Replier (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name.\n");
+        use.append("               Default broker: "+DEFAULT_USER_NAME+"\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -m mode      Replier operating mode - uppercase or lowercase.\n");
+        use.append("               Default mode: "+DEFAULT_MODE+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicRequestor.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicRequestor.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicRequestor.java
new file mode 100644
index 0000000..4c48fab
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/RequestReply/TopicRequestor.java
@@ -0,0 +1,241 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+ Sample Application
+
+Writing a Basic JMS Application using:
+    - Synchronous Request/Reply
+    - Publish/Subscribe
+    - javax.jms.TopicRequestor class
+    - JMSReplyTo Header
+
+When this program runs, it reads input from System.in
+and then sends the text as a message to the topic
+"progress.samples.request".
+
+A "Replier" class should be waiting for the request.
+It will reply with a message.
+
+NOTE: You must run the TopicReplier first.
+(Otherwise the syncronous request will block forever.)
+
+Usage:
+  java TopicRequestor -b <broker:port> -u <username> -p <password>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+                     Default: SampleRequestor
+      -p password    password for user (not checked)
+                     Default: password
+
+Suggested demonstration:
+  - In a console window with the environment set,
+    start a copy of the Replier. For example:
+       java TopicReplier -u SampleReplier
+  - In another console window, start a Requestor.
+    For example:
+       java TopicRequestor -u SampleRequestor
+  - Enter text in the Requestor window then press Enter.
+  
+    The Replier responds with the message in all uppercase characters.
+  - Start other Requestors with different user names to see that
+    replies are not broadcast to all users. For example:
+       java TopicRequestor -u SampleRequestorToo
+
+  - Start other Repliers.
+  - See that all repliers are receiving all the messages,(as they should).
+  - See the Requestor only receives one response.
+       java TopicReplier -u toLower -m lowercase
+*/
+import org.apache.activemq.*;
+
+
+public class TopicRequestor
+{
+    private static final String APP_TOPIC = "jms.samples.request";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_USER_NAME = "SampleRequestor";
+    private static final String DEFAULT_PASSWORD = "password";
+
+    private javax.jms.TopicConnection connect = null;
+    private javax.jms.TopicSession session = null;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void start ( String broker, String username, String password)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.TopicConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createTopicConnection (username, password);
+            session = connect.createTopicSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Topic for all requests.  TopicRequestor will be created
+        // as needed.
+        javax.jms.Topic topic = null;
+        try
+        {
+            topic = session.createTopic (APP_TOPIC);
+            // Now that all setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+          try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            System.out.println ("\nRequestor application:\n"
+			            					+ "============================\n"
+			            					+ "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+											+ "The application uses a TopicRequestor to on the " + APP_TOPIC + " topic."
+											+ "The Replier application gets the message, and transforms it."
+			                                + "The Requestor application displays the result.\n\n"
+			                                + "Type some mixed case text, and then press Enter to make a request.\n");
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 )
+                {
+                    javax.jms.TextMessage msg = session.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // Instead of publishing, we will use a TopicRequestor.
+                    javax.jms.TopicRequestor requestor = new javax.jms.TopicRequestor(session, topic);
+                    javax.jms.Message response = requestor.request(msg);
+                    // The message should be a TextMessage.  Just report it.
+                    javax.jms.TextMessage textMessage = (javax.jms.TextMessage) response;
+                    System.out.println( "[Reply] " + textMessage.getText() );
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = DEFAULT_USER_NAME;
+        String password  = DEFAULT_PASSWORD;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for the "chat".
+        TopicRequestor requestor = new TopicRequestor();
+        requestor.start (broker, username, password);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java Requestor (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name.\n");
+        use.append("               Default broker: "+DEFAULT_USER_NAME+"\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/SelectorChat/SelectorChat.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/SelectorChat/SelectorChat.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/SelectorChat/SelectorChat.java
new file mode 100644
index 0000000..64c9a77
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/SelectorChat/SelectorChat.java
@@ -0,0 +1,296 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+Sample Application
+
+Writing a Basic JMS Application using Publish and Subscribe using
+Message Selectors
+
+This sample publishes messages and sets a property in the message header when
+publishing messages. The subscriber set a message selector to select these
+messages. In this sample we name the property "Department"
+
+Usage:
+  java SelectorChat -b <broker:port> -u <username> -p <password> -v <property> -s <selector>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    (optional) password for user (not checked)
+                     Default: password
+      -s selection   required, selection value to set to message property
+
+
+Suggested demonstration:
+  - In separate console windows with the environment set,
+    start instances of the application
+    under unique user names.
+    For example:
+       java SelectorChat -u BOB -s MARKETING
+       java SelectorChat -u JANE -s MARKETING
+  - Enter text and then press Enter to publish the message.
+  - See messages appear under the various user names as you
+    enter messages in each console window.
+  - Try starting a new instance with a different message selector
+  - Stop a session by pressing CTRL+C in its console window.
+
+*/
+
+import org.apache.activemq.*;
+
+
+public class SelectorChat
+    implements javax.jms.MessageListener
+{
+    private static final String APP_TOPIC = "jms.samples.chat";
+    private static final String PROPERTY_NAME = "Department";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+
+    private javax.jms.Connection connect  = null;
+    private javax.jms.Session pubSession  = null;
+    private javax.jms.Session subSession  = null;
+    private javax.jms.MessageProducer publisher = null;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void chatter( String broker, String username, String password, String selection)
+    {
+
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            pubSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+            subSession = connect.createSession(false,javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Publisher and Subscriber to 'chat' topics
+
+        try
+        {
+            javax.jms.Topic topic = pubSession.createTopic (APP_TOPIC);
+            // NOTE: The subscriber's message selector will now be set:
+            javax.jms.MessageConsumer subscriber = subSession.createConsumer(topic, PROPERTY_NAME + " = \'" + selection +"\'", false);
+            subscriber.setMessageListener(this);
+            publisher = pubSession.createProducer(topic);
+            // Now that setup is complete, start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        try
+        {
+            // Read all standard input and send it as a message.
+
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );		   
+		        System.out.println ("\nSelectorChat application:\n"
+			            	  + "===========================\n"
+			            	  + "The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".\n"
+							  + "The application will publish messages with " + PROPERTY_NAME + " set to " + selection + " to the " + APP_TOPIC + " topic .\n" 	
+							  + "The application also subscribes to that topic, selecting only messages where " + PROPERTY_NAME + " is " + selection + ".\n"
+							  + "Type some text, and then press Enter to publish it as a TextMesssage from " + username + ".\n");
+		   
+            while ( true )
+            {
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if ( s.length() > 0 )
+                {
+                    javax.jms.TextMessage msg = pubSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // NOTE: here we set a property on messages to be published:
+                    msg.setStringProperty(PROPERTY_NAME, selection);
+                    publisher.send( msg );
+                }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources and then exit. */
+    private void exit()
+    {
+        try
+        {
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = null;
+        String password  = DEFAULT_PASSWORD;
+        String selection  = null;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+            // Options
+            if (!arg.startsWith("-")) {
+                System.err.println ("error: unexpected argument - "+arg);
+                printUsage();
+                System.exit(1);
+            }
+            else {
+                if (arg.equals("-b")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing broker name:port");
+                        System.exit(1);
+                    }
+                    broker = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-u")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing user name");
+                        System.exit(1);
+                    }
+                    username = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-p")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing password");
+                        System.exit(1);
+                    }
+                    password = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-s")) {
+                    if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                        System.err.println("error: missing selection");
+                        System.exit(1);
+                    }
+                    selection = argv[++i];
+                    continue;
+                }
+
+                if (arg.equals("-h")) {
+                    printUsage();
+                    System.exit(1);
+                }
+            }
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+        }
+
+        if (selection == null) {
+            System.err.println ("error: selection must be supplied");
+            printUsage();
+            System.exit(1);
+        }
+
+        // Start the JMS client for the "chat".
+        SelectorChat chat = new SelectorChat();
+        chat.chatter (broker, username, password, selection);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java SelectorChat (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port  Specify name:port of broker.\n");
+        use.append("                Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name       Specify unique user name. (Required)\n");
+        use.append("  -p password   Specify password for user.\n");
+        use.append("                Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -s selection  Message selector value. (Required)\n");
+        use.append("  -h            This help screen\n");
+        System.err.println (use);
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/activemq/blob/2ecf41d0/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/TransactedChat/TransactedChat.java
----------------------------------------------------------------------
diff --git a/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/TransactedChat/TransactedChat.java b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/TransactedChat/TransactedChat.java
new file mode 100644
index 0000000..3122783
--- /dev/null
+++ b/assembly/src/release/examples/openwire/exploring-jms/TopicPubSubSamples/TransactedChat/TransactedChat.java
@@ -0,0 +1,296 @@
+/*
+ * � 2001-2009, Progress Software Corporation and/or its subsidiaries or affiliates.  All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ 
+Sample Application
+
+Writing a Basic JMS Application using
+    - Publish and Subscribe
+    - Transacted Sessions
+    - Multiple Sessions
+
+Run this program to publish and subscribe to the specified topic.
+Messages are buffered and sent when a specific string is seen ("COMMIT").
+Messages buffered can be discarded by entering a specified string ("CANCEL").
+
+Usage:
+  java TransactedChat -b <broker:port> -u <username> -p <password>
+      -b broker:port points to your message broker
+                     Default: tcp://localhost:61616
+      -u username    must be unique (but is not checked)
+      -p password    password for user (not checked)
+
+Suggested demonstration:
+  - In a console window with the environment set, start this
+    application. In other console windows start other sessions
+    under different user names. For example:
+       java TransactedChat -u ADMINISTRATION
+       java TransactedChat -u FACILITIES
+  - Type some text and then press Enter.
+  - Repeat to create a batch of messages.
+  - Send the batched messages by entering the text "COMMIT"
+  - Discard the batched messages by entering the text "CANCEL"
+    
+
+*/
+import org.apache.activemq.*;
+
+public class TransactedChat
+    implements javax.jms.MessageListener
+{
+    private static final String APP_TOPIC = "jms.samples.chat";
+    private static final String DEFAULT_BROKER_NAME = "tcp://localhost:61616";
+    private static final String DEFAULT_PASSWORD = "password";
+
+    private javax.jms.Connection connect = null;
+    private javax.jms.Session publishSession = null;
+    private javax.jms.Session subscribeSession = null;
+    private javax.jms.MessageProducer publisher = null;
+
+    /** Create JMS client for publishing and subscribing to messages. */
+    private void chatter( String broker, String username, String password)
+    {
+        // Create a connection.
+        try
+        {
+            javax.jms.ConnectionFactory factory;
+            factory = new ActiveMQConnectionFactory(username, password, broker);
+            connect = factory.createConnection (username, password);
+            // We want to be able up commit/rollback messages published,
+            // but not affect messages consumed. Therefore, we need two sessions.
+            publishSession = connect.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE);
+            subscribeSession = connect.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            System.err.println("error: Cannot connect to Broker - " + broker);
+            jmse.printStackTrace();
+            System.exit(1);
+        }
+
+        // Create Publisher and Subscriber to 'chat' topics
+        try
+        {
+            javax.jms.Topic topic = subscribeSession.createTopic (APP_TOPIC);
+            javax.jms.MessageConsumer subscriber = subscribeSession.createConsumer(topic);
+            subscriber.setMessageListener(this);
+            publisher = publishSession.createProducer(topic);
+            // Now start the Connection
+            connect.start();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        try
+        {
+            // Read all standard input and send it as a message.
+            java.io.BufferedReader stdin =
+                new java.io.BufferedReader( new java.io.InputStreamReader( System.in ) );
+            boolean showMessage = true;
+            while ( true )
+            {
+                if (showMessage)
+                {
+                    System.out.println ("TransactedChat application:");
+	                System.out.println ("===========================" );
+                    System.out.println ("The application user " + username + " connects to the broker at " + DEFAULT_BROKER_NAME + ".");
+					System.out.println ("The application will stage messages to the " + APP_TOPIC + " topic until you either commit them or roll them back.");
+				    System.out.println ("The application also subscribes to that topic to consume any committed messages published there.\n");
+                    System.out.println ("1. Enter text to publish and then press Enter to stage the message.");
+                    System.out.println ("2. Add a few messages to the transaction batch.");
+                    System.out.println ("3. Then, either:");
+                    System.out.println ("     o Enter the text 'COMMIT', and press Enter to publish all the staged messages.");
+                    System.out.println ("     o Enter the text 'CANCEL', and press Enter to drop the staged messages waiting to be sent.");
+                    showMessage = false;
+                }
+                String s = stdin.readLine();
+
+                if ( s == null )
+                    exit();
+                else if (s.trim().equals("CANCEL"))
+                {
+                    // Rollback the messages. A new transaction is implicitly
+                    // started for following messages.
+                    System.out.println ("Cancelling messages...");
+                    publishSession.rollback();
+                    System.out.println ("Staged messages have been cleared.");
+                    showMessage = false; // don't show the help message again.
+                }
+                else if ( s.length() > 0 )
+                // See if we should send the messages
+                  if (s.trim().equals("COMMIT"))
+                  {
+                        // Commit (send) the messages. A new transaction is
+                        // implicitly  started for following messages.
+                        System.out.println ("Committing messages... ");
+                        publishSession.commit();
+                        System.out.println ("Staged messages have all been sent.");
+                        showMessage = false; // dont't show the help message again.
+                  }
+                  else
+                   {
+                    javax.jms.TextMessage msg = publishSession.createTextMessage();
+                    msg.setText( username + ": " + s );
+                    // Publish the message persistently
+                    publisher.send( msg );
+                   }
+            }
+        }
+        catch ( java.io.IOException ioe )
+        {
+            ioe.printStackTrace();
+        }
+        catch ( javax.jms.JMSException jmse )
+        {
+            jmse.printStackTrace();
+        }
+    }
+
+    /**
+     * Handle the message
+     * (as specified in the javax.jms.MessageListener interface).
+     */
+    public void onMessage( javax.jms.Message aMessage)
+    {
+        try
+        {
+            // Cast the message as a text message.
+            javax.jms.TextMessage textMessage = (javax.jms.TextMessage) aMessage;
+
+            // This handler reads a single String from the
+            // message and prints it to the standard output.
+            try
+            {
+                String string = textMessage.getText();
+                System.out.println( string );
+            }
+            catch (javax.jms.JMSException jmse)
+            {
+                jmse.printStackTrace();
+            }
+        }
+        catch (java.lang.RuntimeException rte)
+        {
+            rte.printStackTrace();
+        }
+    }
+
+    /** Cleanup resources cleanly and exit. */
+    private void exit()
+    {
+        try
+        {
+            publishSession.rollback(); // Rollback any uncommitted messages.
+            connect.close();
+        }
+        catch (javax.jms.JMSException jmse)
+        {
+            jmse.printStackTrace();
+        }
+
+        System.exit(0);
+    }
+
+    //
+    // NOTE: the remainder of this sample deals with reading arguments
+    // and does not utilize any JMS classes or code.
+    //
+
+    /** Main program entry point. */
+    public static void main(String argv[]) {
+
+        // Is there anything to do?
+        if (argv.length == 0) {
+            printUsage();
+            System.exit(1);
+        }
+
+        // Values to be read from parameters
+        String broker    = DEFAULT_BROKER_NAME;
+        String username  = null;
+        String password  = DEFAULT_PASSWORD;
+
+        // Check parameters
+        for (int i = 0; i < argv.length; i++) {
+            String arg = argv[i];
+
+
+            if (arg.equals("-b")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing broker name:port");
+                    System.exit(1);
+                }
+                broker = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-u")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing user name");
+                    System.exit(1);
+                }
+                username = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-p")) {
+                if (i == argv.length - 1 || argv[i+1].startsWith("-")) {
+                    System.err.println("error: missing password");
+                    System.exit(1);
+                }
+                password = argv[++i];
+                continue;
+            }
+
+            if (arg.equals("-h")) {
+                printUsage();
+                System.exit(1);
+            }
+
+            // Invalid argument
+            System.err.println ("error: unexpected argument: "+arg);
+            printUsage();
+            System.exit(1);
+        }
+
+        // Check values read in.
+        if (username == null) {
+            System.err.println ("error: user name must be supplied");
+            printUsage();
+        }
+
+        // Start the JMS client for the "chat".
+        TransactedChat chat = new TransactedChat();
+        chat.chatter (broker, username, password);
+
+    }
+
+    /** Prints the usage. */
+    private static void printUsage() {
+
+        StringBuffer use = new StringBuffer();
+        use.append("usage: java TransactedChat (options) ...\n\n");
+        use.append("options:\n");
+        use.append("  -b name:port Specify name:port of broker.\n");
+        use.append("               Default broker: "+DEFAULT_BROKER_NAME+"\n");
+        use.append("  -u name      Specify unique user name. (Required)\n");
+        use.append("  -p password  Specify password for user.\n");
+        use.append("               Default password: "+DEFAULT_PASSWORD+"\n");
+        use.append("  -h           This help screen.\n");
+        System.err.println (use);
+    }
+}
+


Mime
View raw message