[jboss-cvs] JBoss Messaging SVN: r6865 - in trunk/examples: core and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue May 19 04:59:33 EDT 2009


Author: timfox
Date: 2009-05-19 04:59:33 -0400 (Tue, 19 May 2009)
New Revision: 6865

Added:
   trunk/examples/core/
   trunk/examples/core/embedded/
   trunk/examples/core/embedded/build.xml
   trunk/examples/core/embedded/src/
   trunk/examples/core/embedded/src/org/
   trunk/examples/core/embedded/src/org/jboss/
   trunk/examples/core/embedded/src/org/jboss/jms/
   trunk/examples/core/embedded/src/org/jboss/jms/example/
   trunk/examples/core/embedded/src/org/jboss/jms/example/EmbeddedExample.java
Modified:
   trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java
Log:
core embedded example

Added: trunk/examples/core/embedded/build.xml
===================================================================
--- trunk/examples/core/embedded/build.xml	                        (rev 0)
+++ trunk/examples/core/embedded/build.xml	2009-05-19 08:59:33 UTC (rev 6865)
@@ -0,0 +1,43 @@
+<?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 Embedded Example">
+
+   <import file="../common/build.xml"/>
+
+   <target name="run">   	
+      <antcall target="runExample">
+         <param name="example.classname" value="org.jboss.jms.example.EmbeddedExample"/>
+         <!-- We limit the client to running in only 50MB of RAM -->
+     	   <param name="java-min-memory" value="50M"/>
+     	   <param name="java-max-memory" value="50M"/>
+      </antcall>
+   </target>
+</project>

Added: trunk/examples/core/embedded/src/org/jboss/jms/example/EmbeddedExample.java
===================================================================
--- trunk/examples/core/embedded/src/org/jboss/jms/example/EmbeddedExample.java	                        (rev 0)
+++ trunk/examples/core/embedded/src/org/jboss/jms/example/EmbeddedExample.java	2009-05-19 08:59:33 UTC (rev 6865)
@@ -0,0 +1,128 @@
+/*
+   * 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 java.util.Date;
+
+import javax.jms.TextMessage;
+
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.Configuration;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory;
+import org.jboss.messaging.core.server.Messaging;
+import org.jboss.messaging.core.server.MessagingServer;
+
+/**
+ * 
+ * This exammple shows how to run a JBoss Messaging core client and server embedded in your
+ * own application
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class EmbeddedExample
+{
+
+   public static void main(String[] args)
+   {
+      try
+      {
+         
+         // Step 1. Create the Configuration, and set the properties accordingly
+         Configuration configuration = new ConfigurationImpl();
+         configuration.setEnablePersistence(false);
+         configuration.setSecurityEnabled(false);
+         
+         // Step 2. Create and start the server
+         MessagingServer server = Messaging.newMessagingServer(configuration);
+         server.start();
+   
+   
+         // Step 3. As we are not using a JNDI environment we instantiate the objects directly         
+         ClientSessionFactory sf = new ClientSessionFactoryImpl (new TransportConfiguration(InVMConnectorFactory.class.getName()));
+         
+         // Step 4. Create a core queue
+         ClientSession coreSession = sf.createSession(false, false, false);
+         
+         final String queueName = "queue.exampleQueue";
+         
+         coreSession.createQueue(queueName, queueName, true);
+         
+         coreSession.close();
+                  
+         ClientSession session = null;
+   
+         try
+         {
+   
+            // Step 5. Create the session, and producer
+            session = sf.createSession(false, true, true);
+            
+                       
+            ClientProducer producer = session.createProducer(queueName);
+   
+            // Step 6. Create and send a message
+            ClientMessage message = session.createClientMessage(false);
+            
+            final String propName = "myprop";
+            
+            message.putStringProperty(propName, "Hello sent at " + new Date());
+            
+            System.out.println("Sending the message.");
+            
+            producer.send(message);
+
+            // Step 7. Create the message consumer and start the connection
+            ClientConsumer messageConsumer = session.createConsumer(queueName);
+            session.start();
+   
+            // Step 8. Receive the message. 
+            ClientMessage messageReceived = messageConsumer.receive(1000);
+            System.out.println("Received TextMessage:" + messageReceived.getProperty(propName));
+         }
+         finally
+         {
+            // Step 9. Be sure to close our resources!
+            if (session != null)
+            {
+               session.close();
+            }
+            
+            // Step 10. Stop the server
+            server.stop();
+         }
+      }
+      catch (Exception e)
+      {
+         e.printStackTrace();
+         System.exit(-1);
+      }
+   }
+
+}

Modified: trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java
===================================================================
--- trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java	2009-05-19 08:19:46 UTC (rev 6864)
+++ trunk/examples/jms/embedded/src/org/jboss/jms/example/EmbeddedExample.java	2009-05-19 08:59:33 UTC (rev 6865)
@@ -41,7 +41,7 @@
 import org.jboss.messaging.jms.client.JBossConnectionFactory;
 
 /**
- * This example demonstrates how to run JBoss Messaging embedded
+ * This example demonstrates how to run a JBoss Messaging embedded with JMS
  * 
  * @author <a href="clebert.suconic at jboss.com">Clebert Suconic</a>
  */




More information about the jboss-cvs-commits mailing list