[jboss-cvs] JBoss Messaging SVN: r4063 - in trunk/docs/examples: jms and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 15 11:12:34 EDT 2008
Author: ataylor
Date: 2008-04-15 11:12:34 -0400 (Tue, 15 Apr 2008)
New Revision: 4063
Added:
trunk/docs/examples/build.properties
trunk/docs/examples/jms/
trunk/docs/examples/jms/build.xml
trunk/docs/examples/jms/etc/
trunk/docs/examples/jms/etc/jndi.properties
trunk/docs/examples/jms/src/
trunk/docs/examples/jms/src/org/
trunk/docs/examples/jms/src/org/jboss/
trunk/docs/examples/jms/src/org/jboss/jms/
trunk/docs/examples/jms/src/org/jboss/jms/example/
trunk/docs/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java
trunk/docs/examples/jms/src/org/jboss/jms/example/QueueExample.java
trunk/docs/examples/jms/src/org/jboss/jms/example/TopicExample.java
Removed:
trunk/docs/examples/bridge/
trunk/docs/examples/common/
trunk/docs/examples/distributed-queue/
trunk/docs/examples/distributed-topic/
trunk/docs/examples/ejb3mdb/
trunk/docs/examples/embedded/
trunk/docs/examples/examples.properties
trunk/docs/examples/http/
trunk/docs/examples/mdb-failure/
trunk/docs/examples/mdb/
trunk/docs/examples/queue-failover/
trunk/docs/examples/queue/
trunk/docs/examples/secure-socket/
trunk/docs/examples/stateless-clustered/
trunk/docs/examples/stateless/
trunk/docs/examples/topic/
trunk/docs/examples/web-service/
Log:
new examples - first go
Added: trunk/docs/examples/build.properties
===================================================================
--- trunk/docs/examples/build.properties (rev 0)
+++ trunk/docs/examples/build.properties 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,3 @@
+#Tue Apr 15 10:48:39 GMT+00:00 2008
+lib.dir=../../../thirdparty
+client.jar=../../../build/jars/jboss-messaging-client.jar
Deleted: trunk/docs/examples/examples.properties
===================================================================
--- trunk/docs/examples/examples.properties 2008-04-15 14:10:33 UTC (rev 4062)
+++ trunk/docs/examples/examples.properties 2008-04-15 15:12:34 UTC (rev 4063)
@@ -1,2 +0,0 @@
-messaging.client.jar.path=../../../output/lib
-remoting.path=../../../src/etc/remoting
Added: trunk/docs/examples/jms/build.xml
===================================================================
--- trunk/docs/examples/jms/build.xml (rev 0)
+++ trunk/docs/examples/jms/build.xml 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- 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. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- $Id: build.xml 4037 2008-04-11 13:12:57Z ataylor $ -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project default="compile" name="JBoss Messaging JMS Examples">
+
+ <property file="../build.properties"/>
+
+ <property name="src.dir" value="src"/>
+ <property name="etc.dir" value="etc"/>
+ <property name="build.dir" value="build"/>
+
+ <path id="compile.classpath">
+ <fileset dir="${lib.dir}">
+ <include name="**/*.jar"/>
+ </fileset>
+ </path>
+
+ <path id="runtime.classpath">
+ <path refid="compile.classpath"/>
+ <pathelement location="${build.dir}"/>
+ <pathelement location="${etc.dir}"/>
+ <pathelement location="${client.jar}"/>
+ </path>
+
+ <target name="clean">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <target name="init">
+ <mkdir dir="${build.dir}"/>
+ </target>
+
+
+ <target name="compile" depends="init">
+ <javac srcdir="${src.dir}" destdir="${build.dir}" debug="on"
+ source="1.5">
+ <classpath refid="compile.classpath"/>
+ </javac>
+ </target>
+
+ <target name="queueExample" depends="compile">
+ <java classname="org.jboss.jms.example.QueueExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="topicExample" depends="compile">
+ <java classname="org.jboss.jms.example.TopicExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="DurSubExample" depends="compile">
+ <java classname="org.jboss.jms.example.DurableSubscriberExample" fork="true">
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+</project>
\ No newline at end of file
Added: trunk/docs/examples/jms/etc/jndi.properties
===================================================================
--- trunk/docs/examples/jms/etc/jndi.properties (rev 0)
+++ trunk/docs/examples/jms/etc/jndi.properties 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,3 @@
+java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
+java.naming.provider.url=jnp://localhost:1099
+java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
\ No newline at end of file
Added: trunk/docs/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java
===================================================================
--- trunk/docs/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java (rev 0)
+++ trunk/docs/examples/jms/src/org/jboss/jms/example/DurableSubscriberExample.java 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.jboss.jms.example;
+
+import javax.jms.*;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+/**
+ * A simple JMS Durable Subscriber example.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class DurableSubscriberExample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Topic topic = (Topic) initialContext.lookup("/topic/testTopic");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ connection.setClientID("myclientid");
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ session.createDurableSubscriber(topic, "myuniqueid");
+ connection.close();
+
+ connection = cf.createConnection();
+ connection.setClientID("myclientid");
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer messageProducer = session.createProducer(topic);
+ Message message = session.createTextMessage("This is a text message!");
+ messageProducer.send(message);
+ TopicSubscriber topicSubscriber = session.createDurableSubscriber(topic, "myuniqueid");
+ connection.start();
+ TextMessage message2 = (TextMessage) topicSubscriber.receive();
+ System.out.println("message = " + message2.getText());
+ topicSubscriber.close();
+ session.unsubscribe("myuniqueid");
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException jmsException)
+ {
+ jmsException.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+}
Added: trunk/docs/examples/jms/src/org/jboss/jms/example/QueueExample.java
===================================================================
--- trunk/docs/examples/jms/src/org/jboss/jms/example/QueueExample.java (rev 0)
+++ trunk/docs/examples/jms/src/org/jboss/jms/example/QueueExample.java 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+package org.jboss.jms.example;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.*;
+import java.util.ResourceBundle;
+import java.util.Properties;
+
+/**
+ * A simple JMS Queue example that creates a producer and consumer on a queue and sends a message.
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class QueueExample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Queue queue = (Queue) initialContext.lookup("/queue/testQueue");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer producer = session.createProducer(queue);
+ Message message = session.createTextMessage("This is a text message!");
+ producer.send(message);
+ MessageConsumer messageConsumer = session.createConsumer(queue);
+ connection.start();
+ TextMessage message2 = (TextMessage) messageConsumer.receive(5000);
+ System.out.println("message = " + message2.getText());
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if(connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
Added: trunk/docs/examples/jms/src/org/jboss/jms/example/TopicExample.java
===================================================================
--- trunk/docs/examples/jms/src/org/jboss/jms/example/TopicExample.java (rev 0)
+++ trunk/docs/examples/jms/src/org/jboss/jms/example/TopicExample.java 2008-04-15 15:12:34 UTC (rev 4063)
@@ -0,0 +1,102 @@
+/*
+ * 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.
+ */
+package org.jboss.jms.example;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.*;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * A simple JMS Topic example that creates a producer and consumer on a queue and sends and receives a message via a
+ * Message Listener..
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class TopicExample
+{
+ public static void main(String[] args)
+ {
+ Connection connection = null;
+ try
+ {
+ //create an initial context, env will be picked up from jndi.properties
+ InitialContext initialContext = new InitialContext();
+ Topic topic = (Topic) initialContext.lookup("/topic/testTopic");
+ ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");
+ connection = cf.createConnection();
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ MessageProducer messageProducer = session.createProducer(topic);
+
+ MessageConsumer messageConsumer = session.createConsumer(topic);
+ Message message = session.createTextMessage("This is a text message!");
+ final CountDownLatch latch = new CountDownLatch(1);
+ messageConsumer.setMessageListener(new MessageListener()
+ {
+ public void onMessage(Message message)
+ {
+ try
+ {
+ TextMessage textMessage = (TextMessage) message;
+ System.out.println("message = " + textMessage.getText());
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ latch.countDown();
+ }
+ });
+ connection.start();
+
+ messageProducer.send(message);
+
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException e)
+ {
+ }
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JMSException jmsException)
+ {
+ jmsException.printStackTrace();
+ }
+ finally
+ {
+ if (connection != null)
+ try
+ {
+ connection.close();
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+}
More information about the jboss-cvs-commits
mailing list