[jboss-cvs] JBoss Messaging SVN: r6528 - trunk/examples/javaee/servlet-transport.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 23 03:46:28 EDT 2009
Author: gaohoward
Date: 2009-04-23 03:46:28 -0400 (Thu, 23 Apr 2009)
New Revision: 6528
Modified:
trunk/examples/javaee/servlet-transport/readme.html
Log:
finish readme for servlet example
Modified: trunk/examples/javaee/servlet-transport/readme.html
===================================================================
--- trunk/examples/javaee/servlet-transport/readme.html 2009-04-22 16:38:22 UTC (rev 6527)
+++ trunk/examples/javaee/servlet-transport/readme.html 2009-04-23 07:46:28 UTC (rev 6528)
@@ -1,20 +1,72 @@
<html>
<head>
- <title>JBoss Messaging Java EE MDB Example</title>
+ <title>JBoss Messaging Java EE Servlet Example</title>
<link rel="stylesheet" type="text/css" href="../../jms/common/common.css">
</head>
<body>
- <h1>Java EE MDB Example</h1>
+ <h1>Java EE Servlet Example</h1>
<br>
- <p>This example shows you how to end a message to an MDB</p>
+ <p>This example shows you how to configure and use servlet transport with JBoss Messaging.</p>
<p>
- The example will send deploy a simple MDB and demonstrate sending a message and the MDB consuming it
+ JBoss Messaging supports different transports through configuration. In fact JBoss Messaging provides a set of
+ simple SPI that allow new transports can be plugged in easily. In this example, netty's servlet transport is
+ configured and used in sending and receiving messages with JBoss Message Server.
+
+ To enable netty's servlet transport, following these steps
+
+ <ol>
+ <li>Create a servlet</li>
+ There is a servlet for this example under config. Please take a look at config/jms-servlet/WEB-INF/web.xml for
+ details of the servlet configuration. The servlet is used to accept requests and send response.
+
+ <li>Add servlet connector/acceptor entries in jbm-configuration.xml</li>
+ The corresponding connector/acceptor need to be configured to tell JBoss Messaging to use netty servlet transport.
+ The configure looks like:
+ <p>
+
+ <pre><code>
+ <connectors>
+ ...
+ <connector name="netty-servlet">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyConnectorFactory</factory-class>
+ <param key="jbm.remoting.netty.host" value="localhost" type="String"/>
+ <param key="jbm.remoting.netty.port" value="8080" type="Integer"/>
+ <param key="jbm.remoting.netty.useservlet" value="true" type="Boolean"/>
+ <param key="jbm.remoting.netty.servletpath" value="/jms-servlet/JBMServlet" type="String"/>
+ </connector>
+ ...
+ </connectors>
+
+ <acceptors>
+ ...
+ <acceptor name="netty-servlet">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ <param key="jbm.remoting.netty.useinvm" value="true" type="Boolean"/>
+ <param key="jbm.remoting.netty.host" value="org.jboss.jbm" type="String"/>
+ </acceptor>
+ ...
+ </acceptor>
+ </code></pre>
+ </p>
+ <li>You also need to use the Connection Factory that has configured to use the servlet connector in jbm-jms.xml, as</li>
+ <p>
+ <pre><code>
+ <connection-factory name="TestServletConnectionFactory">
+ <connector-ref connector-name="netty-servlet"/>
+ <entries>
+ <entry name="/TestServletConnectionFactory"/>
+ </entries>
+ </connection-factory>
+ </code></pre>
+ </p>
+ </ol>
</p>
<h2>Example step-by-step</h2>
- <p><i>To deploy the example, simply type <code>ant deploy</code> from this directory **</i></p>
- <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
- <p><i>To undeploy the example, simply type <code>ant undeploy</code> from this directory **</i></p>
- <p><i> ** make sure that JBOSS_HOME is set to the Jboss installation directory</i></p>
+ <p><i>To run the example, first you need to install a JBoss AS 5 server and set JBOSS_HOME environment accordingly.
+ Then you need to create a AS server profile with JBoss Messaging service, and start AS with that profile.
+ From this directory, type <code>ant</code>. This will cause the servlet to be deployed to AS and then it runs
+ the example undeploy the servlet in the end.</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>jndi.properties</code> file in the directory <code>config</code></li>
@@ -29,7 +81,7 @@
<li>We look up the JMS connection factory object from JNDI</li>
<pre>
- <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+ <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/TestServletConnectionFactory");</code>
</pre>
<li>We create a JMS connection</li>
@@ -57,20 +109,20 @@
<code>messageProducer.send(message);</code>
</pre>
- <li>The MDB receives the message<br />
- We know the message is a TextMessage so we cast to it.
- </li>
+ <li>We create a JMS Message Consumer</li>
<pre>
- <code>TextMessage tm = (TextMessage)message;</code>
+ <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
</pre>
- <li>The MDB gets the text and prints it
- </li>
+ <li>We start the connection</li>
<pre>
- <code>String text = tm.getText();
- System.out.println("message " + text + " received");
- </code>
+ <code>connection.start();</code>
</pre>
+
+ <li>We receive the message</li>
+ <pre>
+ <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);</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>
More information about the jboss-cvs-commits
mailing list