[jboss-cvs] JBoss Messaging SVN: r6361 - in trunk/examples/jms: topic-selector-example1 and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 8 08:23:17 EDT 2009
Author: gaohoward
Date: 2009-04-08 08:23:17 -0400 (Wed, 08 Apr 2009)
New Revision: 6361
Added:
trunk/examples/jms/topic-selector-example1/
trunk/examples/jms/topic-selector-example1/build.xml
trunk/examples/jms/topic-selector-example1/readme.html
trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample1.java
trunk/examples/jms/topic-selector-example2/
trunk/examples/jms/topic-selector-example2/build.xml
trunk/examples/jms/topic-selector-example2/readme.html
trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/TopicSelectorExample2.java
Removed:
trunk/examples/jms/selector/
trunk/examples/jms/topic-selector-example1/build.xml
trunk/examples/jms/topic-selector-example1/readme.html
trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample.java
trunk/examples/jms/topic-selector-example2/build.xml
trunk/examples/jms/topic-selector-example2/readme.html
trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/SelectorExample.java
trunk/examples/jms/topic-selector/
Log:
rename topic examples
Copied: trunk/examples/jms/topic-selector-example1 (from rev 6358, trunk/examples/jms/topic-selector)
Property changes on: trunk/examples/jms/topic-selector-example1
___________________________________________________________________
Name: svn:ignore
+ build
Name: svn:mergeinfo
+
Deleted: trunk/examples/jms/topic-selector-example1/build.xml
===================================================================
--- trunk/examples/jms/topic-selector/build.xml 2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector-example1/build.xml 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE project [
- <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
- ]>
-
-<!-- =========================================================================================== -->
-<!-- -->
-<!-- JBoss, Home of Professional Open Source -->
-<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
-<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
-<!-- full listing of individual contributors. -->
-<!-- -->
-<!-- This is free software; you can redistribute it and/or modify it -->
-<!-- under the terms of the GNU Lesser General Public License as -->
-<!-- published by the Free Software Foundation; either version 2.1 of -->
-<!-- the License, or (at your option) any later version. -->
-<!-- -->
-<!-- This software is distributed in the hope that it will be useful, -->
-<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
-<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
-<!-- Lesser General Public License for more details. -->
-<!-- -->
-<!-- You should have received a copy of the GNU Lesser General Public -->
-<!-- License along with this software; if not, write to the Free -->
-<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
-<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
-<!-- -->
-<!-- =========================================================================================== -->
-
-
-<project default="run" name="JBoss Messaging JMS Topic Selector Example">
-
- <import file="../common/build.xml"/>
-
- <target name="run">
- <antcall target="runExample">
- <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample"/>
- </antcall>
- </target>
-
- <target name="runRemote">
- <antcall target="runExample">
- <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample"/>
- <param name="jbm.example.runServer" value="false"/>
- </antcall>
- </target>
-
-</project>
Copied: trunk/examples/jms/topic-selector-example1/build.xml (from rev 6359, trunk/examples/jms/topic-selector/build.xml)
===================================================================
--- trunk/examples/jms/topic-selector-example1/build.xml (rev 0)
+++ trunk/examples/jms/topic-selector-example1/build.xml 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- JBoss, Home of Professional Open Source -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
+<!-- full listing of individual contributors. -->
+<!-- -->
+<!-- This is free software; you can redistribute it and/or modify it -->
+<!-- under the terms of the GNU Lesser General Public License as -->
+<!-- published by the Free Software Foundation; either version 2.1 of -->
+<!-- the License, or (at your option) any later version. -->
+<!-- -->
+<!-- This software is distributed in the hope that it will be useful, -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
+<!-- Lesser General Public License for more details. -->
+<!-- -->
+<!-- You should have received a copy of the GNU Lesser General Public -->
+<!-- License along with this software; if not, write to the Free -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JMS Topic Selector Example 1">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample1"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample1"/>
+ <param name="jbm.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
Deleted: trunk/examples/jms/topic-selector-example1/readme.html
===================================================================
--- trunk/examples/jms/topic-selector/readme.html 2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector-example1/readme.html 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,157 +0,0 @@
-<html>
- <head>
- <title>JBoss Messaging JMS Topic With Selectors Example</title>
- <link rel="stylesheet" type="text/css" href="../common/common.css">
- </head>
- <body>
- <h1>JMS Topic Example</h1>
- <br>
- <p>This example shows you how to send message to a JMS Topic, and subscribe them using selectors with JBoss Messaging, also creating 3 non durable subscribers. 2 subscriptions using selectors, and a third one that should receive the complete set of messages.</p>
- <p>Topics and selectors are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>
- <p>A regular subscriber would receive every message sent to the topic, but when you use a selector you would limit the messages you receive by the logic expression you choose only getting the messages that will matter to your processing.</p>
- <br>
- <h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
- <br>
- <ol>
- <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
- <pre>
- <code>initialContext = getContext();</code>
- </pre>
-
- <li>We look-up the JMS topic object from JNDI</li>
- <pre>
- <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code>
- </pre>
-
- <li>We look-up the JMS connection factory object from JNDI</li>
- <pre>
- <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create a JMS connection</li>
- <pre>
- <code>connection = cf.createConnection();</code>
- </pre>
-
- <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
- <pre>
- <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
- </pre>
-
- <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
- <pre>
- <code>MessageProducer messageProducer = session.createProducer(topic);</code>
- </pre>
-
- <li>Create one non-durable subscriber with a specific filter</li>
- <pre>
- <code>MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);</code>
- </pre>
-
- <li>Create a second non-durable subscriber with a specific filter</li>
- <pre>
- <code>MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);</code>
- </pre>
-
- <li>Create a third non-durable subscriber without any filters, and it should receive the complete set of messages</li>
- <pre>
- <code>MessageConsumer messageConsumer3 = session.createConsumer(topic, "someID=2", false);</code>
- </pre>
-
- <li>Send 20 messages, 10 with someID=1, 10 with someID=2 </li>
- <pre><code>
- for (int i = 1; i < 10; i++)
- {
- for (int someID = 1; someID <= 2; someID++)
- {
- TextMessage message1 = session.createTextMessage("This is a text message " + i +
- " sent for someID=" +
- someID);
-
- message1.setIntProperty("someID", someID);
-
- producer.send(message1);
-
- System.out.println("Sent message: " + message1.getText());
- }
- }</code></pre>
-
- <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
- <pre> <code>connection.start();</code>
- </pre>
-
-
- <li>Consume the messages from MessageConsumer1, filtering out someID=2</li>
- <pre><code>
- for (;;)
- {
- TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
- if (messageReceivedA == null)
- {
- break;
- }
-
- System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
- " someID = " +
- messageReceivedA.getIntProperty("someID"));
- }</code></pre>
-
- <li>Consume the messages from MessageConsumer2, filtering out someID=1</li>
- <pre><code>
- for (;;)
- {
- TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
- if (messageReceivedB == null)
- {
- break;
- }
-
- System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
- " someID = " +
- messageReceivedB.getIntProperty("someID"));
- }</code></pre>
-
- <li>Consume the messages from MessageConsumer3, receiving the complete set of messages</li>
- <pre><code>
- for (;;)
- {
- TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
- if (messageReceivedC == null)
- {
- break;
- }
- System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
- " someID = " +
- messageReceivedC.getIntProperty("someID"));
- }</code></pre>
-
- <li>Close the consumers</li>
- <pre><code>subscriberA.close();</code></pre>
- <pre><code>subscriberB.close();</code></pre>
-
- <li>Delete the subscriptions when you're done</li>
- <pre><code>session.unsubscribe("sub-a1");</code></pre>
- <pre><code>session.unsubscribe("sub-a2");</code></pre>
-
- <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre>
- <code>finally
- {
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }</code>
- </pre>
-
-
-
- </ol>
- </body>
-</html>
\ No newline at end of file
Copied: trunk/examples/jms/topic-selector-example1/readme.html (from rev 6359, trunk/examples/jms/topic-selector/readme.html)
===================================================================
--- trunk/examples/jms/topic-selector-example1/readme.html (rev 0)
+++ trunk/examples/jms/topic-selector-example1/readme.html 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,157 @@
+<html>
+ <head>
+ <title>JBoss Messaging JMS Topic Selector Example 1</title>
+ <link rel="stylesheet" type="text/css" href="../common/common.css">
+ </head>
+ <body>
+ <h1>JMS Topic Selector Example 1</h1>
+ <br>
+ <p>This example shows you how to send message to a JMS Topic, and subscribe them using selectors with JBoss Messaging, also creating 3 non durable subscribers. 2 subscriptions using selectors, and a third one that should receive the complete set of messages.</p>
+ <p>Topics and selectors are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>
+ <p>A regular subscriber would receive every message sent to the topic, but when you use a selector you would limit the messages you receive by the logic expression you choose only getting the messages that will matter to your processing.</p>
+ <br>
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+ <br>
+ <ol>
+ <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
+ <pre>
+ <code>initialContext = getContext();</code>
+ </pre>
+
+ <li>We look-up the JMS topic object from JNDI</li>
+ <pre>
+ <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code>
+ </pre>
+
+ <li>We look-up the JMS connection factory object from JNDI</li>
+ <pre>
+ <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+ </pre>
+
+ <li>We create a JMS connection</li>
+ <pre>
+ <code>connection = cf.createConnection();</code>
+ </pre>
+
+ <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+ <pre>
+ <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+ </pre>
+
+ <li>Create one non-durable subscriber with a specific filter</li>
+ <pre>
+ <code>MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);</code>
+ </pre>
+
+ <li>Create a second non-durable subscriber with a specific filter</li>
+ <pre>
+ <code>MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);</code>
+ </pre>
+
+ <li>Create a third non-durable subscriber without any filters, and it should receive the complete set of messages</li>
+ <pre>
+ <code>MessageConsumer messageConsumer3 = session.createConsumer(topic, "someID=2", false);</code>
+ </pre>
+
+ <li>Send 20 messages, 10 with someID=1, 10 with someID=2 </li>
+ <pre><code>
+ for (int i = 1; i < 10; i++)
+ {
+ for (int someID = 1; someID <= 2; someID++)
+ {
+ TextMessage message1 = session.createTextMessage("This is a text message " + i +
+ " sent for someID=" +
+ someID);
+
+ message1.setIntProperty("someID", someID);
+
+ producer.send(message1);
+
+ System.out.println("Sent message: " + message1.getText());
+ }
+ }</code></pre>
+
+ <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
+ <pre> <code>connection.start();</code>
+ </pre>
+
+
+ <li>Consume the messages from MessageConsumer1, filtering out someID=2</li>
+ <pre><code>
+ for (;;)
+ {
+ TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
+ if (messageReceivedA == null)
+ {
+ break;
+ }
+
+ System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
+ " someID = " +
+ messageReceivedA.getIntProperty("someID"));
+ }</code></pre>
+
+ <li>Consume the messages from MessageConsumer2, filtering out someID=1</li>
+ <pre><code>
+ for (;;)
+ {
+ TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
+ if (messageReceivedB == null)
+ {
+ break;
+ }
+
+ System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
+ " someID = " +
+ messageReceivedB.getIntProperty("someID"));
+ }</code></pre>
+
+ <li>Consume the messages from MessageConsumer3, receiving the complete set of messages</li>
+ <pre><code>
+ for (;;)
+ {
+ TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
+ if (messageReceivedC == null)
+ {
+ break;
+ }
+ System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
+ " someID = " +
+ messageReceivedC.getIntProperty("someID"));
+ }</code></pre>
+
+ <li>Close the consumers</li>
+ <pre><code>subscriberA.close();</code></pre>
+ <pre><code>subscriberB.close();</code></pre>
+
+ <li>Delete the subscriptions when you're done</li>
+ <pre><code>session.unsubscribe("sub-a1");</code></pre>
+ <pre><code>session.unsubscribe("sub-a2");</code></pre>
+
+ <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+ <pre>
+ <code>finally
+ {
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Deleted: trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample.java
===================================================================
--- trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample.java 2009-04-08 11:50:03 UTC (rev 6358)
+++ trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample.java 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,173 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.example;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-/**
- * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message.
- *
- * @author <a href="csuconic at redhat.com">Clebert Suconic</a>
- */
-public class TopicSelectorExample extends JMSExample
-{
- public static void main(String[] args)
- {
- new TopicSelectorExample().run(args);
- }
-
- public boolean runExample() throws Exception
- {
- Connection connection = null;
-
- InitialContext initialContext = null;
- try
- {
-
- // Step 1. Create an initial context to perform the JNDI lookup.
- initialContext = getContext(0);
-
- // Step 2. Look-up the JMS topic
- Topic topic = (Topic)initialContext.lookup("/topic/exampleTopic");
-
- // Step 3. Look-up the JMS connection factory
- ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
-
- // Step 4. Create a JMS connection
- connection = cf.createConnection();
-
- // Step 5. Create a JMS session
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // Step 6. Create a JMS message producer
- MessageProducer producer = session.createProducer(topic);
-
- // Step 7. Create one subscription with a specific Filter for someID=1
- MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);
-
- // Step 8. Create another subscription with a specific Filter for someID=2
- MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);
-
- // Step 9. Create another subscription with no filters, which will receive every message sent to the topic
- MessageConsumer messageConsumer3 = session.createConsumer(topic);
-
- // Step 10. Send 20 messages, 10 with someID=1, 10 with someID=2
-
- for (int i = 1; i < 10; i++)
- {
- for (int someID = 1; someID <= 2; someID++)
- {
- // Step 10.1 Create a text message
- TextMessage message1 = session.createTextMessage("This is a text message " + i +
- " sent for someID=" +
- someID);
-
- // Step 10.1 Set a property
- message1.setIntProperty("someID", someID);
-
- // Step 10.2 Send the message
- producer.send(message1);
-
- System.out.println("Sent message: " + message1.getText());
- }
- }
-
- // Step 11. Start the JMS Connection. This step will activate the subscribers to receive messages.
- connection.start();
-
- // Step 12. Consume the messages from MessageConsumer1, filtering out someID=2
-
- System.out.println("*************************************************************");
- System.out.println("MessageConsumer1 will only receive messages where someID=1:");
- for (;;)
- {
- TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
- if (messageReceivedA == null)
- {
- break;
- }
-
- System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
- " someID = " +
- messageReceivedA.getIntProperty("someID"));
- }
-
- // Step 13. Consume the messages from MessageConsumer2, filtering out someID=2
- System.out.println("*************************************************************");
- System.out.println("MessageConsumer2 will only receive messages where someID=2:");
- for (;;)
- {
- TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
- if (messageReceivedB == null)
- {
- break;
- }
-
- System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
- " someID = " +
- messageReceivedB.getIntProperty("someID"));
- }
-
- // Step 14. Consume the messages from MessageConsumer3, receiving the complete set of messages
- System.out.println("*************************************************************");
- System.out.println("MessageConsumer3 will receive every message:");
- for (;;)
- {
- TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
- if (messageReceivedC == null)
- {
- break;
- }
- System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
- " someID = " +
- messageReceivedC.getIntProperty("someID"));
- }
-
- // Step 15. Close the subscribers
- messageConsumer1.close();
- messageConsumer2.close();
- messageConsumer3.close();
-
- return true;
-
- }
- finally
- {
- // Step 15. Be sure to close our JMS resources!
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }
- }
-}
Copied: trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample1.java (from rev 6359, trunk/examples/jms/topic-selector/src/org/jboss/jms/example/TopicSelectorExample1.java)
===================================================================
--- trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample1.java (rev 0)
+++ trunk/examples/jms/topic-selector-example1/src/org/jboss/jms/example/TopicSelectorExample1.java 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message.
+ *
+ * @author <a href="csuconic at redhat.com">Clebert Suconic</a>
+ */
+public class TopicSelectorExample1 extends JMSExample
+{
+ public static void main(String[] args)
+ {
+ new TopicSelectorExample1().run(args);
+ }
+
+ public boolean runExample() throws Exception
+ {
+ Connection connection = null;
+
+ InitialContext initialContext = null;
+ try
+ {
+
+ // Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = getContext(0);
+
+ // Step 2. Look-up the JMS topic
+ Topic topic = (Topic)initialContext.lookup("/topic/exampleTopic");
+
+ // Step 3. Look-up the JMS connection factory
+ ConnectionFactory cf = (ConnectionFactory)initialContext.lookup("/ConnectionFactory");
+
+ // Step 4. Create a JMS connection
+ connection = cf.createConnection();
+
+ // Step 5. Create a JMS session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 6. Create a JMS message producer
+ MessageProducer producer = session.createProducer(topic);
+
+ // Step 7. Create one subscription with a specific Filter for someID=1
+ MessageConsumer messageConsumer1 = session.createConsumer(topic, "someID=1", false);
+
+ // Step 8. Create another subscription with a specific Filter for someID=2
+ MessageConsumer messageConsumer2 = session.createConsumer(topic, "someID=2", false);
+
+ // Step 9. Create another subscription with no filters, which will receive every message sent to the topic
+ MessageConsumer messageConsumer3 = session.createConsumer(topic);
+
+ // Step 10. Send 20 messages, 10 with someID=1, 10 with someID=2
+
+ for (int i = 1; i < 10; i++)
+ {
+ for (int someID = 1; someID <= 2; someID++)
+ {
+ // Step 10.1 Create a text message
+ TextMessage message1 = session.createTextMessage("This is a text message " + i +
+ " sent for someID=" +
+ someID);
+
+ // Step 10.1 Set a property
+ message1.setIntProperty("someID", someID);
+
+ // Step 10.2 Send the message
+ producer.send(message1);
+
+ System.out.println("Sent message: " + message1.getText());
+ }
+ }
+
+ // Step 11. Start the JMS Connection. This step will activate the subscribers to receive messages.
+ connection.start();
+
+ // Step 12. Consume the messages from MessageConsumer1, filtering out someID=2
+
+ System.out.println("*************************************************************");
+ System.out.println("MessageConsumer1 will only receive messages where someID=1:");
+ for (;;)
+ {
+ TextMessage messageReceivedA = (TextMessage)messageConsumer1.receive(1000);
+ if (messageReceivedA == null)
+ {
+ break;
+ }
+
+ System.out.println("messageConsumer1 received " + messageReceivedA.getText() +
+ " someID = " +
+ messageReceivedA.getIntProperty("someID"));
+ }
+
+ // Step 13. Consume the messages from MessageConsumer2, filtering out someID=2
+ System.out.println("*************************************************************");
+ System.out.println("MessageConsumer2 will only receive messages where someID=2:");
+ for (;;)
+ {
+ TextMessage messageReceivedB = (TextMessage)messageConsumer2.receive(1000);
+ if (messageReceivedB == null)
+ {
+ break;
+ }
+
+ System.out.println("messageConsumer2 received " + messageReceivedB.getText() +
+ " someID = " +
+ messageReceivedB.getIntProperty("someID"));
+ }
+
+ // Step 14. Consume the messages from MessageConsumer3, receiving the complete set of messages
+ System.out.println("*************************************************************");
+ System.out.println("MessageConsumer3 will receive every message:");
+ for (;;)
+ {
+ TextMessage messageReceivedC = (TextMessage)messageConsumer3.receive(1000);
+ if (messageReceivedC == null)
+ {
+ break;
+ }
+ System.out.println("messageConsumer3 received " + messageReceivedC.getText() +
+ " someID = " +
+ messageReceivedC.getIntProperty("someID"));
+ }
+
+ // Step 15. Close the subscribers
+ messageConsumer1.close();
+ messageConsumer2.close();
+ messageConsumer3.close();
+
+ return true;
+
+ }
+ finally
+ {
+ // Step 15. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+}
Copied: trunk/examples/jms/topic-selector-example2 (from rev 6359, trunk/examples/jms/selector)
Property changes on: trunk/examples/jms/topic-selector-example2
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted: trunk/examples/jms/topic-selector-example2/build.xml
===================================================================
--- trunk/examples/jms/selector/build.xml 2009-04-08 12:16:01 UTC (rev 6359)
+++ trunk/examples/jms/topic-selector-example2/build.xml 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE project [
- <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
- ]>
-
-<!-- =========================================================================================== -->
-<!-- -->
-<!-- JBoss, Home of Professional Open Source -->
-<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
-<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
-<!-- full listing of individual contributors. -->
-<!-- -->
-<!-- This is free software; you can redistribute it and/or modify it -->
-<!-- under the terms of the GNU Lesser General Public License as -->
-<!-- published by the Free Software Foundation; either version 2.1 of -->
-<!-- the License, or (at your option) any later version. -->
-<!-- -->
-<!-- This software is distributed in the hope that it will be useful, -->
-<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
-<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
-<!-- Lesser General Public License for more details. -->
-<!-- -->
-<!-- You should have received a copy of the GNU Lesser General Public -->
-<!-- License along with this software; if not, write to the Free -->
-<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
-<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
-<!-- -->
-<!-- =========================================================================================== -->
-
-
-<project default="run" name="JBoss Messaging JMS Selector Example">
-
- <import file="../common/build.xml"/>
-
- <target name="run">
- <antcall target="runExample">
- <param name="example.classname" value="org.jboss.jms.example.SelectorExample"/>
- </antcall>
- </target>
-
- <target name="runRemote">
- <antcall target="runExample">
- <param name="example.classname" value="org.jboss.jms.example.SelectorExample"/>
- <param name="jbm.example.runServer" value="false"/>
- </antcall>
- </target>
-
-</project>
Copied: trunk/examples/jms/topic-selector-example2/build.xml (from rev 6360, trunk/examples/jms/selector/build.xml)
===================================================================
--- trunk/examples/jms/topic-selector-example2/build.xml (rev 0)
+++ trunk/examples/jms/topic-selector-example2/build.xml 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- JBoss, Home of Professional Open Source -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
+<!-- full listing of individual contributors. -->
+<!-- -->
+<!-- This is free software; you can redistribute it and/or modify it -->
+<!-- under the terms of the GNU Lesser General Public License as -->
+<!-- published by the Free Software Foundation; either version 2.1 of -->
+<!-- the License, or (at your option) any later version. -->
+<!-- -->
+<!-- This software is distributed in the hope that it will be useful, -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
+<!-- Lesser General Public License for more details. -->
+<!-- -->
+<!-- You should have received a copy of the GNU Lesser General Public -->
+<!-- License along with this software; if not, write to the Free -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="run" name="JBoss Messaging JMS Selector Example 2">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample2"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.TopicSelectorExample2"/>
+ <param name="jbm.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
Deleted: trunk/examples/jms/topic-selector-example2/readme.html
===================================================================
--- trunk/examples/jms/selector/readme.html 2009-04-08 12:16:01 UTC (rev 6359)
+++ trunk/examples/jms/topic-selector-example2/readme.html 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,136 +0,0 @@
-<html>
- <head>
- <title>JBoss Messaging JMS Selector Example</title>
- <link rel="stylesheet" type="text/css" href="../common/common.css">
- </head>
- <body>
- <h1>JMS Selector Example</h1>
- <br>
- <p>This example shows you how to selectively consume messages using message selectors.</p>
-
- <p>Message selectors are strings with special syntax that can be used in creating consumers. Message consumers
- that are thus created only receive messages that match its selector. On message delivering, the JBoss Message
- Server evaluates the corresponding message headers of the messages against each selector, if any, and then delivers
- the 'matched' messages to its consumer. Please consult the JMS 1.1 specification for full details.</p>
-
- <p>In this example, three message consumers are created on a topic. The first consumer is created with selector
- <code>'color=red'</code>, it only receives messages that
- have a 'color' string property of 'red' value; the second is created with selector <code>'color=green'</code>, it
- only receives messages who have a 'color' string property of
- 'green' value; and the thrid without a selector, which means it receives all messages. To illustrate, three messages
- with different 'color' property values are created and sent.</p>
- <br>
- <h2>Example step-by-step</h2>
- <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
- <br>
- <ol>
- <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
- <pre>
- <code>InitialContext initialContext = getContext();</code>
- </pre>
-
- <li>We look-up the JMS topic object from JNDI</li>
- <pre>
- <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code>
- </pre>
-
- <li>We look-up the JMS connection factory object from JNDI</li>
- <pre>
- <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
- </pre>
-
- <li>We create a JMS connection</li>
- <pre>
- <code>connection = cf.createConnection();</code>
- </pre>
-
- <li>We start the connection</li>
- <pre>
- <code>connection.start();</code>
- </pre>
-
- <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
- <pre>
- <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
- </pre>
-
- <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
- <pre>
- <code>MessageProducer messageProducer = session.createProducer(topic);</code>
- </pre>
-
- <li>We create two selectors.</li>
- <pre>
- <code>
- String redSelector = "color='red'";
- String greenSelector = "color='green'";
- </code>
- </pre>
-
- <li>We Create a JMS Message Consumer that receives 'red' messages.</li>
- <pre>
- <code>
- MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
- redConsumer.setMessageListener(new SimpleMessageListener("red"));
- </code>
- </pre>
-
- <li>We Create a second JMS Message Consumer that receives 'green' messages.</li>
- <pre>
- <code>
- MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
- greenConsumer.setMessageListener(new SimpleMessageListener("green"));
- </code>
- </pre>
-
- <li>We Create another JMS Message Consumer that receives all messages.</li>
- <pre>
- <code>
- MessageConsumer allConsumer = session.createConsumer(topic);
- allConsumer.setMessageListener(new SimpleMessageListener("all"));
- </code>
- </pre>
-
- <li>We Create three messages, each has a different color property.</li>
- <pre>
- <code>
- TextMessage redMessage = session.createTextMessage("Red");
- redMessage.setStringProperty("color", "red");
- TextMessage greenMessage = session.createTextMessage("Green");
- greenMessage.setStringProperty("color", "green");
- TextMessage blueMessage = session.createTextMessage("Blue");
- blueMessage.setStringProperty("color", "blue");
- </code>
- </pre>
-
- <li>We send the messages to the topic</li>
- <pre>
- <code>
- producer.send(redMessage);
- System.out.println("Message sent: " + redMessage.getText());
- producer.send(greenMessage);
- System.out.println("Message sent: " + greenMessage.getText());
- producer.send(blueMessage);
- System.out.println("Message sent: " + blueMessage.getText());
- </code>
- </pre>
-
- <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
-
- <pre>
- <code>finally
- {
- if (initialContext != null)
- {
- initialContext.close();
- }
- if (connection != null)
- {
- connection.close();
- }
- }</code>
- </pre>
-
- </ol>
- </body>
-</html>
\ No newline at end of file
Copied: trunk/examples/jms/topic-selector-example2/readme.html (from rev 6360, trunk/examples/jms/selector/readme.html)
===================================================================
--- trunk/examples/jms/topic-selector-example2/readme.html (rev 0)
+++ trunk/examples/jms/topic-selector-example2/readme.html 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,136 @@
+<html>
+ <head>
+ <title>JBoss Messaging JMS Topic Selector Example 2</title>
+ <link rel="stylesheet" type="text/css" href="../common/common.css">
+ </head>
+ <body>
+ <h1>JMS Selector Example 2</h1>
+ <br>
+ <p>This example shows you how to selectively consume messages using message selectors.</p>
+
+ <p>Message selectors are strings with special syntax that can be used in creating consumers. Message consumers
+ that are thus created only receive messages that match its selector. On message delivering, the JBoss Message
+ Server evaluates the corresponding message headers of the messages against each selector, if any, and then delivers
+ the 'matched' messages to its consumer. Please consult the JMS 1.1 specification for full details.</p>
+
+ <p>In this example, three message consumers are created on a topic. The first consumer is created with selector
+ <code>'color=red'</code>, it only receives messages that
+ have a 'color' string property of 'red' value; the second is created with selector <code>'color=green'</code>, it
+ only receives messages who have a 'color' string property of
+ 'green' value; and the thrid without a selector, which means it receives all messages. To illustrate, three messages
+ with different 'color' property values are created and sent.</p>
+ <br>
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+ <br>
+ <ol>
+ <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
+ <pre>
+ <code>InitialContext initialContext = getContext();</code>
+ </pre>
+
+ <li>We look-up the JMS topic object from JNDI</li>
+ <pre>
+ <code>Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");</code>
+ </pre>
+
+ <li>We look-up the JMS connection factory object from JNDI</li>
+ <pre>
+ <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+ </pre>
+
+ <li>We create a JMS connection</li>
+ <pre>
+ <code>connection = cf.createConnection();</code>
+ </pre>
+
+ <li>We start the connection</li>
+ <pre>
+ <code>connection.start();</code>
+ </pre>
+
+ <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+ <pre>
+ <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+ </pre>
+
+ <li>We create two selectors.</li>
+ <pre>
+ <code>
+ String redSelector = "color='red'";
+ String greenSelector = "color='green'";
+ </code>
+ </pre>
+
+ <li>We Create a JMS Message Consumer that receives 'red' messages.</li>
+ <pre>
+ <code>
+ MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
+ redConsumer.setMessageListener(new SimpleMessageListener("red"));
+ </code>
+ </pre>
+
+ <li>We Create a second JMS Message Consumer that receives 'green' messages.</li>
+ <pre>
+ <code>
+ MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
+ greenConsumer.setMessageListener(new SimpleMessageListener("green"));
+ </code>
+ </pre>
+
+ <li>We Create another JMS Message Consumer that receives all messages.</li>
+ <pre>
+ <code>
+ MessageConsumer allConsumer = session.createConsumer(topic);
+ allConsumer.setMessageListener(new SimpleMessageListener("all"));
+ </code>
+ </pre>
+
+ <li>We Create three messages, each has a different color property.</li>
+ <pre>
+ <code>
+ TextMessage redMessage = session.createTextMessage("Red");
+ redMessage.setStringProperty("color", "red");
+ TextMessage greenMessage = session.createTextMessage("Green");
+ greenMessage.setStringProperty("color", "green");
+ TextMessage blueMessage = session.createTextMessage("Blue");
+ blueMessage.setStringProperty("color", "blue");
+ </code>
+ </pre>
+
+ <li>We send the messages to the topic</li>
+ <pre>
+ <code>
+ producer.send(redMessage);
+ System.out.println("Message sent: " + redMessage.getText());
+ producer.send(greenMessage);
+ System.out.println("Message sent: " + greenMessage.getText());
+ producer.send(blueMessage);
+ System.out.println("Message sent: " + blueMessage.getText());
+ </code>
+ </pre>
+
+ <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+ <pre>
+ <code>finally
+ {
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Deleted: trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/SelectorExample.java
===================================================================
--- trunk/examples/jms/selector/src/org/jboss/jms/example/SelectorExample.java 2009-04-08 12:16:01 UTC (rev 6359)
+++ trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/SelectorExample.java 2009-04-08 12:23:17 UTC (rev 6361)
@@ -1,159 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.jms.example;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.jms.Topic;
-import javax.naming.InitialContext;
-
-/**
- * A simple JMS example that consumes messages using selectors.
- *
- * @author <a href="hgao at redhat.com">Howard Gao</a>
- */
-public class SelectorExample extends JMSExample
-{
- private volatile boolean result = true;
-
- public static void main(String[] args)
- {
- new SelectorExample().run(args);
- }
-
- public boolean runExample() throws Exception
- {
- Connection connection = null;
- InitialContext initialContext = null;
- try
- {
- ///Step 1. Create an initial context to perform the JNDI lookup.
- initialContext = getContext(0);
-
- //Step 2. perform a lookup on the topic
- Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
-
- //Step 3. perform a lookup on the Connection Factory
- ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
-
- //Step 4. Create a JMS Connection
- connection = cf.createConnection();
-
- //Step 5. Start the Connection
- connection.start();
-
- //Step 6. Create a JMS Session
- Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- //Step 7. Create a Message Producer
- MessageProducer producer = session.createProducer(topic);
-
- //Step 8. Prepare two selectors
- String redSelector = "color='red'";
- String greenSelector = "color='green'";
-
- //Step 9. Create a JMS Message Consumer that receives 'red' messages
- MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
- redConsumer.setMessageListener(new SimpleMessageListener("red"));
-
- //Step 10. Create a second JMS message consumer that receives 'green' messages
- MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
- greenConsumer.setMessageListener(new SimpleMessageListener("green"));
-
- //Step 11. Create another JMS message consumer that receives all messages.
- MessageConsumer allConsumer = session.createConsumer(topic);
- allConsumer.setMessageListener(new SimpleMessageListener("all"));
-
- //Step 12. Create three messages, each has a color property
- TextMessage redMessage = session.createTextMessage("Red");
- redMessage.setStringProperty("color", "red");
- TextMessage greenMessage = session.createTextMessage("Green");
- greenMessage.setStringProperty("color", "green");
- TextMessage blueMessage = session.createTextMessage("Blue");
- blueMessage.setStringProperty("color", "blue");
-
- //Step 13. Send the Messages
- producer.send(redMessage);
- System.out.println("Message sent: " + redMessage.getText());
- producer.send(greenMessage);
- System.out.println("Message sent: " + greenMessage.getText());
- producer.send(blueMessage);
- System.out.println("Message sent: " + blueMessage.getText());
-
- Thread.sleep(5000);
-
- return result;
- }
- finally
- {
- //Step 14. Be sure to close our JMS resources!
- if (connection != null)
- {
- connection.close();
- }
-
- // Also the initialContext
- if (initialContext != null)
- {
- initialContext.close();
- }
- }
- }
-
- public class SimpleMessageListener implements MessageListener
- {
-
- private String name;
-
- public SimpleMessageListener(String listener)
- {
- name = listener;
- }
-
- public void onMessage(Message msg)
- {
- TextMessage textMessage = (TextMessage)msg;
- try
- {
- String colorProp = msg.getStringProperty("color");
- System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp);
- if ((!colorProp.equals(name)) && (!name.equals("all")))
- {
- result = false;
- }
- }
- catch (JMSException e)
- {
- e.printStackTrace();
- result = false;
- }
- }
-
- }
-}
Copied: trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/TopicSelectorExample2.java (from rev 6360, trunk/examples/jms/selector/src/org/jboss/jms/example/TopicSelectorExample2.java)
===================================================================
--- trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/TopicSelectorExample2.java (rev 0)
+++ trunk/examples/jms/topic-selector-example2/src/org/jboss/jms/example/TopicSelectorExample2.java 2009-04-08 12:23:17 UTC (rev 6361)
@@ -0,0 +1,159 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jms.example;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+import javax.naming.InitialContext;
+
+/**
+ * A simple JMS example that consumes messages using selectors.
+ *
+ * @author <a href="hgao at redhat.com">Howard Gao</a>
+ */
+public class TopicSelectorExample2 extends JMSExample
+{
+ private volatile boolean result = true;
+
+ public static void main(String[] args)
+ {
+ new TopicSelectorExample2().run(args);
+ }
+
+ public boolean runExample() throws Exception
+ {
+ Connection connection = null;
+ InitialContext initialContext = null;
+ try
+ {
+ ///Step 1. Create an initial context to perform the JNDI lookup.
+ initialContext = getContext(0);
+
+ //Step 2. perform a lookup on the topic
+ Topic topic = (Topic) initialContext.lookup("/topic/exampleTopic");
+
+ //Step 3. perform a lookup on the Connection Factory
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+
+ //Step 4. Create a JMS Connection
+ connection = cf.createConnection();
+
+ //Step 5. Start the Connection
+ connection.start();
+
+ //Step 6. Create a JMS Session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ //Step 7. Create a Message Producer
+ MessageProducer producer = session.createProducer(topic);
+
+ //Step 8. Prepare two selectors
+ String redSelector = "color='red'";
+ String greenSelector = "color='green'";
+
+ //Step 9. Create a JMS Message Consumer that receives 'red' messages
+ MessageConsumer redConsumer = session.createConsumer(topic, redSelector);
+ redConsumer.setMessageListener(new SimpleMessageListener("red"));
+
+ //Step 10. Create a second JMS message consumer that receives 'green' messages
+ MessageConsumer greenConsumer = session.createConsumer(topic, greenSelector);
+ greenConsumer.setMessageListener(new SimpleMessageListener("green"));
+
+ //Step 11. Create another JMS message consumer that receives all messages.
+ MessageConsumer allConsumer = session.createConsumer(topic);
+ allConsumer.setMessageListener(new SimpleMessageListener("all"));
+
+ //Step 12. Create three messages, each has a color property
+ TextMessage redMessage = session.createTextMessage("Red");
+ redMessage.setStringProperty("color", "red");
+ TextMessage greenMessage = session.createTextMessage("Green");
+ greenMessage.setStringProperty("color", "green");
+ TextMessage blueMessage = session.createTextMessage("Blue");
+ blueMessage.setStringProperty("color", "blue");
+
+ //Step 13. Send the Messages
+ producer.send(redMessage);
+ System.out.println("Message sent: " + redMessage.getText());
+ producer.send(greenMessage);
+ System.out.println("Message sent: " + greenMessage.getText());
+ producer.send(blueMessage);
+ System.out.println("Message sent: " + blueMessage.getText());
+
+ Thread.sleep(5000);
+
+ return result;
+ }
+ finally
+ {
+ //Step 14. Be sure to close our JMS resources!
+ if (connection != null)
+ {
+ connection.close();
+ }
+
+ // Also the initialContext
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ }
+ }
+
+ public class SimpleMessageListener implements MessageListener
+ {
+
+ private String name;
+
+ public SimpleMessageListener(String listener)
+ {
+ name = listener;
+ }
+
+ public void onMessage(Message msg)
+ {
+ TextMessage textMessage = (TextMessage)msg;
+ try
+ {
+ String colorProp = msg.getStringProperty("color");
+ System.out.println("Receiver " + name + " receives message [" + textMessage.getText() + "] with color property: " + colorProp);
+ if ((!colorProp.equals(name)) && (!name.equals("all")))
+ {
+ result = false;
+ }
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ result = false;
+ }
+ }
+
+ }
+}
More information about the jboss-cvs-commits
mailing list