|Home > Documentation > Reference > Samples > Sample applications > jms-mdb - JMS and MDB Sample Application|
|jaxws-calculator - Simple Web Service with JAX-WS||Sample applications||ldap-sample-app - LDAP Sample Application|
Asynchronous processing is often appropriate under requirements to maximize throughput possibly at the expense of latency. Java Message Service (JMS) supports a considerable range of asynchronous processing scenarios. Generally it is most appropriate when processing may be divided among a set of components that are under the control of one organization and have reasonably reliable inter-component communication. When the content or format of data to be transferred between components needs to be negotiated among several organizations or communication is less reliable web service solutions may be more appropriate. When the components are sufficiently lightweight or coupled a SEDA solution may be more appropriate.
Javaee message driven beans provide convenient support for components that need to process only one, independent message at a time. More complicated scenarios such as components that need to receive two or more messages to proceed or require in-order delivery are usually better handled with jms apis directly or message routing systems.
This sample provides a very simple example of an MDB supplied from a jms queue. There is a web app to feed the queue.
This article is organized into following sections.
Geronimo uses ActiveMQ as the default jms provider. JMS connectivity is provided through the J2CA connector provided by ActiveMQ. Deploying an instance of this resource adapter sets up connection factories and destinations for use by your application. By default Geronimo starts up an ActiveMQ message broker in the geronimo vm, but the resource adapter can be configured to connect to any ActiveMQ broker whether running inside geronimo or not.
ActiveMQ supports a large variety of transports (such as TCP, SSL, UDP, multicast, intra-JVM, and NIO) and client interactions (such as push, pull, and publish/subscribe).
The order processing application has a message queue for orders. Order requests can be generated and sent via the web application. When order requests are received on the order queue, a MDB will be triggered.
The core of the order placement application will be deployed as an EAR to the application server. Overview of the contents of EAR is given in the following depiction.
The Message-Driven Bean uses the @MessageDriven annotation to replace the declaration of this MDB in the ejb-jar.xml file. By providing the annotation with further information it knows to look for a destination (in this case it happens to be a queue) to process. So this MDB will sit there and process messages passed into the 'OrderQueue.' The end result is that is echoes this message to the screen.
Note the various @ActivationConfigProperty annotations. The property names are specific to the particular resource adapter used. Each resource adapter is required to specify an ActivationSpec javabean and the javabean properties are the allowable propertyNames for these annotations. The ActiveMQ ActivationSpec class is org.apache.activemq.ra.ActiveMQActivationSpec.
In this application there is a MDB that will listen on OrderQueue. The openejb-jar section of the geronimo plan indicates that the OrderRecvMDB MDB uses the jms-resources resource adapter instance.
The connector section of the geronimo plan configures a resource adapter instance named "jms-resources" that has a ConnectionFactory to be used by the web client and the Order queue used by both client and mdb.
The OrderSenderServlet.java servlet will parse the web form, create a message, and send that message to the OrderQueue via the CommonConnectoryFactory.
Please note that Geronimo ignores the 'mappedName' configuration attribute for @Resource. Instead, use 'name' when annotating.
web.xml of the archive has the relevant configurations for the both queue connection factory and the queue, which is essential to refer to resources in a local enviroment.
Please note that this web application supports Servlet 2.5 specification. Some of the configurations in older versions (2.4) are slightly different than given in the above web.xml.
The geronimo plan does not need to include details about the web component as the annotations will help resolve the queue or connection factory references.
To test the sample web application open a browser and type http://localhost:8080/order. It will forward you in to the Order Management Welcome page. Then user has to fill the necessary information for the order placement and submit it.
After processing an order you will see the message printed to your console.
This article has demonstrated the use of JMS features in Apache Geronimo with the ActiveMQ JMS server.
Some of the highlights of this article: