[jboss-cvs] JBoss Messaging SVN: r6881 - in trunk/examples/jms: send-acknowledgements and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 19 09:31:34 EDT 2009
Author: timfox
Date: 2009-05-19 09:31:34 -0400 (Tue, 19 May 2009)
New Revision: 6881
Added:
trunk/examples/jms/send-acknowledgements/
trunk/examples/jms/send-acknowledgements/build.xml
trunk/examples/jms/send-acknowledgements/readme.html
trunk/examples/jms/send-acknowledgements/server0/
trunk/examples/jms/send-acknowledgements/server0/client-jndi.properties
trunk/examples/jms/send-acknowledgements/server0/jbm-configuration.xml
trunk/examples/jms/send-acknowledgements/server0/jbm-jboss-beans.xml
trunk/examples/jms/send-acknowledgements/server0/jbm-jms.xml
trunk/examples/jms/send-acknowledgements/server0/jbm-users.xml
trunk/examples/jms/send-acknowledgements/src/
trunk/examples/jms/send-acknowledgements/src/org/
trunk/examples/jms/send-acknowledgements/src/org/jboss/
trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/
trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/example/
trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/example/SendAcknowledgementsExample.java
Log:
added send acks example
Property changes on: trunk/examples/jms/send-acknowledgements
___________________________________________________________________
Name: svn:ignore
+ build
logs
Added: trunk/examples/jms/send-acknowledgements/build.xml
===================================================================
--- trunk/examples/jms/send-acknowledgements/build.xml (rev 0)
+++ trunk/examples/jms/send-acknowledgements/build.xml 2009-05-19 13:31:34 UTC (rev 6881)
@@ -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 Send Acknowledgements Example">
+
+ <import file="../common/build.xml"/>
+
+ <target name="run">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.SendAcknowledgementsExample"/>
+ </antcall>
+ </target>
+
+ <target name="runRemote">
+ <antcall target="runExample">
+ <param name="example.classname" value="org.jboss.jms.example.SendAcknowledgementsExample"/>
+ <param name="jbm.example.runServer" value="false"/>
+ </antcall>
+ </target>
+
+</project>
\ No newline at end of file
Added: trunk/examples/jms/send-acknowledgements/readme.html
===================================================================
--- trunk/examples/jms/send-acknowledgements/readme.html (rev 0)
+++ trunk/examples/jms/send-acknowledgements/readme.html 2009-05-19 13:31:34 UTC (rev 6881)
@@ -0,0 +1,117 @@
+<html>
+ <head>
+ <title>JBoss Messaging Asynchronous Send Acknowledgements Example</title>
+ <link rel="stylesheet" type="text/css" href="../common/common.css">
+ </head>
+ <body>
+ <h1>Asynchronous Send Acknowledgements Example</h1>
+ <br>
+ <p>Asynchronous Send Acknowledgements are an advanced feature of JBoss Messaging which allow you to
+ receive acknowledgements that messages were successfully received at the server in a separate stream
+ to the stream of messages being sent to the server.<p/>
+ <p>In this example we create a normal JMS session, then set a SendAcknowledgementHandler on the JMS
+ session's underlying core session. We send many messages to the server without blocking, and asynchronously
+ the server calls the handler when it has successfully received each message.
+ <br>
+ <p>For more information on Asynchronous Send Acknowledgements please see the user manual</p>
+ <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 queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</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>Define a SendAcknowledgementHandler which will receive asynchronous acknowledgements</li>
+ <pre>
+ <code>
+ class MySendAcknowledgementsHandler implements SendAcknowledgementHandler
+ {
+ int count = 0;
+
+ public void sendAcknowledged(final Message message)
+ {
+ System.out.println("Received send acknowledgement for message " + count++);
+ }
+ }
+ </code>
+ </pre>
+
+ <li>Create a JMS session</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>Set the handler on the underlying core session</li>
+ <pre>
+ <code>
+ ClientSession coreSession = ((JBossSession)session).getCoreSession();
+
+ coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler());
+
+ </code>
+ </pre>
+
+ <li>Create a JMS Message Producer</li>
+ <pre>
+ <code>
+ MessageProducer producer = session.createProducer(queue);
+
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ </code>
+ </pre>
+
+ <li>Send 5000 messages, the handler will get called asynchronously some time later after the messages are sent.</li>
+ <pre>
+ <code>
+ final int numMessages = 5000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ javax.jms.Message jmsMessage = session.createMessage();
+
+ producer.send(jmsMessage);
+
+ System.out.println("Sent message " + i);
+ }
+ </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
Property changes on: trunk/examples/jms/send-acknowledgements/server0
___________________________________________________________________
Name: svn:ignore
+ data
logs
Added: trunk/examples/jms/send-acknowledgements/server0/client-jndi.properties
===================================================================
--- trunk/examples/jms/send-acknowledgements/server0/client-jndi.properties (rev 0)
+++ trunk/examples/jms/send-acknowledgements/server0/client-jndi.properties 2009-05-19 13:31:34 UTC (rev 6881)
@@ -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
Added: trunk/examples/jms/send-acknowledgements/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/jms/send-acknowledgements/server0/jbm-configuration.xml (rev 0)
+++ trunk/examples/jms/send-acknowledgements/server0/jbm-configuration.xml 2009-05-19 13:31:34 UTC (rev 6881)
@@ -0,0 +1,36 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+ <!-- Connectors -->
+
+ <connectors>
+ <connector name="netty-connector">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </connector>
+ </connectors>
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.port" value="5446" type="Integer"/>
+ </acceptor>
+ </acceptors>
+
+ <!-- Other config -->
+
+ <security-settings>
+ <!--security for example queue-->
+ <security-setting match="jms.queue.exampleQueue">
+ <permission type="createDurableQueue" roles="guest"/>
+ <permission type="deleteDurableQueue" roles="guest"/>
+ <permission type="createTempQueue" roles="guest"/>
+ <permission type="deleteTempQueue" roles="guest"/>
+ <permission type="consume" roles="guest"/>
+ <permission type="send" roles="guest"/>
+ </security-setting>
+ </security-settings>
+
+</configuration>
Added: trunk/examples/jms/send-acknowledgements/server0/jbm-jboss-beans.xml
===================================================================
--- trunk/examples/jms/send-acknowledgements/server0/jbm-jboss-beans.xml (rev 0)
+++ trunk/examples/jms/send-acknowledgements/server0/jbm-jboss-beans.xml 2009-05-19 13:31:34 UTC (rev 6881)
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Naming" class="org.jnp.server.NamingBeanImpl"/>
+
+ <!-- JNDI server. Disable this if you don't want JNDI -->
+ <bean name="JNDIServer" class="org.jnp.server.Main">
+ <property name="namingInfo">
+ <inject bean="Naming"/>
+ </property>
+ <property name="port">1099</property>
+ <property name="bindAddress">localhost</property>
+ <property name="rmiPort">1098</property>
+ <property name="rmiBindAddress">localhost</property>
+ </bean>
+
+ <!-- MBean server -->
+ <bean name="MBeanServer" class="javax.management.MBeanServer">
+ <constructor factoryClass="java.lang.management.ManagementFactory"
+ factoryMethod="getPlatformMBeanServer"/>
+ </bean>
+
+ <!-- The core configuration -->
+ <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+ <!-- The security manager -->
+ <bean name="JBMSecurityManager" class="org.jboss.messaging.core.security.impl.JBMSecurityManagerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ </bean>
+
+ <!-- The core server -->
+ <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+ <start ignored="true"/>
+ <stop ignored="true"/>
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ <parameter>
+ <inject bean="MBeanServer"/>
+ </parameter>
+ <parameter>
+ <inject bean="JBMSecurityManager"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+ <!-- The JMS server -->
+ <bean name="JMSServerManager" class="org.jboss.messaging.jms.server.impl.JMSServerManagerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="MessagingServer"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/jms/send-acknowledgements/server0/jbm-jms.xml
===================================================================
--- trunk/examples/jms/send-acknowledgements/server0/jbm-jms.xml (rev 0)
+++ trunk/examples/jms/send-acknowledgements/server0/jbm-jms.xml 2009-05-19 13:31:34 UTC (rev 6881)
@@ -0,0 +1,17 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-jms.xsd">
+ <!--the connection factory used by the example-->
+ <connection-factory name="ConnectionFactory">
+ <connector-ref connector-name="netty-connector"/>
+ <entries>
+ <entry name="ConnectionFactory"/>
+ </entries>
+ </connection-factory>
+
+ <!--the queue used by the example-->
+ <queue name="exampleQueue">
+ <entry name="/queue/exampleQueue"/>
+ </queue>
+
+</configuration>
Added: trunk/examples/jms/send-acknowledgements/server0/jbm-users.xml
===================================================================
--- trunk/examples/jms/send-acknowledgements/server0/jbm-users.xml (rev 0)
+++ trunk/examples/jms/send-acknowledgements/server0/jbm-users.xml 2009-05-19 13:31:34 UTC (rev 6881)
@@ -0,0 +1,7 @@
+<configuration xmlns="urn:jboss:messaging" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-users.xsd">
+ <!-- the default user. this is used where username is null-->
+ <defaultuser name="guest" password="guest">
+ <role name="guest"/>
+ </defaultuser>
+</configuration>
\ No newline at end of file
Added: trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/example/SendAcknowledgementsExample.java
===================================================================
--- trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/example/SendAcknowledgementsExample.java (rev 0)
+++ trunk/examples/jms/send-acknowledgements/src/org/jboss/jms/example/SendAcknowledgementsExample.java 2009-05-19 13:31:34 UTC (rev 6881)
@@ -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 javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.naming.InitialContext;
+
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.SendAcknowledgementHandler;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.jms.client.JBossSession;
+
+/**
+ *
+ * Asynchronous Send Acknowledgements are an advanced feature of JBoss Messaging which allow you to
+ * receive acknowledgements that messages were successfully received at the server in a separate stream
+ * to the stream of messages being sent to the server.
+ * For more information please see the readme.html file
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SendAcknowledgementsExample extends JMSExample
+{
+ public static void main(String[] args)
+ {
+ new SendAcknowledgementsExample().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. Perfom a lookup on the queue
+ Queue queue = (Queue)initialContext.lookup("/queue/exampleQueue");
+
+ // 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. Define a SendAcknowledgementHandler which will receive asynchronous acknowledgements
+ class MySendAcknowledgementsHandler implements SendAcknowledgementHandler
+ {
+ int count = 0;
+
+ public void sendAcknowledged(final Message message)
+ {
+ System.out.println("Received send acknowledgement for message " + count++);
+ }
+ }
+
+ // Step 6. Create a JMS Session
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Step 7. Set the handler on the underlying core session
+
+ ClientSession coreSession = ((JBossSession)session).getCoreSession();
+
+ coreSession.setSendAcknowledgementHandler(new MySendAcknowledgementsHandler());
+
+ // Step 6. Create a JMS Message Producer
+ MessageProducer producer = session.createProducer(queue);
+
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ // Step 7. Send 5000 messages, the handler will get called asynchronously some time later after the messages
+ // are sent.
+
+ final int numMessages = 5000;
+
+ for (int i = 0; i < numMessages; i++)
+ {
+ javax.jms.Message jmsMessage = session.createMessage();
+
+ producer.send(jmsMessage);
+
+ System.out.println("Sent message " + i);
+ }
+
+ return true;
+ }
+ finally
+ {
+ // Step 12. Be sure to close our JMS resources!
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ }
+
+}
More information about the jboss-cvs-commits
mailing list