Enterprise messaging has become an increasingly important component of loosely coupled, reliable enterprise frameworks. This is due in large part to the proliferation of enterprise applications and disparate enterprise resources, and the increasing need to integrate these applications into cohesive systems. Introduction of Message Driven Beans (MDBs) in the Enterprise Java Beans 2.0 have served as a solution for this new messaging paradigm. MDBs provides a reusable J2EE messaging component that can leverage existing investments in J2EE application servers, specifically EJBs. Apache Geronimo supports this vital API by integrating one of the best breed open source messaging frameworks ActiveMQ. This article will guide you a way to use MDBs in enterprise application scenario in both as a locally and remotely reffered enviroments with Geronimo and ActiveMQ.
The company reffered in this sample application sales one specific item in both retail and whole sale markets. All the placed orders in the application has to be autorized by a superior staff before delevering goods to the Customer. Order placement of the application can be done in both using company web site or via it's agents. Usually company agents send a list of orders as a consignment. They use a special software installed in their premises while small scaled customers place orders using company web site.
After reading this article you should be able to define MDBs in Geronimo/ActiveMQ enviroment and use them in different kinds of client applications.
This article is organized in to following sections.
- Overview of MDB Features
- Application Overview
- Configuring, Building and Deploying the Sample Application
- Testing of the Sample Application
- Summary
Overview of MDB Features
Application Overview
Following figure gives the overall architecture of the order processing application.
Application contents
The Order Processing application consist of following list of packages and classes.
- org.apache.geronimo.samples.order.client
- ConsignmentSender -
- org.apache.geronimo.samples.order.ejb
- OrderRecvMDB -
- org.apache.geronimo.samples.order.util
- PropertyLoader - Loads configuration properties to the order processing applocation.
- org.apache.geronimo.samples.order.web
- OrderMgmtServlet -
Finally Order Processing application will be deployed as an EAR to the application server. Overview of the contents of EAR is given in the following.
|-Order.ear |-OrderEjb.jar |-META-INF |- ejb-jar.xml |- openejb-jar.xml |-OrderWeb.war |-jsp |- index.jsp |- error.jsp |-WEB-INF |- web.xml |- geronimo-web.xml |- classes |-META-INF |- application.xml |- geronimo-application.xml
First we will look at how the business service layer of the application has been implemented with the help of MDBs. In this application enviroment all the MDBs are using XDoclet to generate their meta information.
Corresponding openejb-jar.xml defines Geronimo specific features of MDBs.
<openejb-jar xmlns="http://www.openejb.org/xml/ns/openejb-jar-2.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1" xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.1"> <sys:environment> <sys:moduleId> <sys:groupId>samples</sys:groupId> <sys:artifactId>OrderEjb</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>car</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>geronimo</sys:groupId> <sys:artifactId>activemq-broker</sys:artifactId> <sys:version>1.1</sys:version> <sys:type>car</sys:type> </sys:dependency> <sys:dependency> <sys:groupId>samples</sys:groupId> <sys:artifactId>jms-resources</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>rar</sys:type> </sys:dependency> </sys:dependencies> <sys:hidden-classes/> <sys:non-overridable-classes/> </sys:environment> <enterprise-beans> <message-driven> <ejb-name>OrderRecvMDB</ejb-name> <resource-adapter> <resource-link>OrderRecvConnectionFactory</resource-link> </resource-adapter> <activation-config> <activation-config-property> <activation-config-property-name>destination</activation-config-property-name> <activation-config-property-value>OrderRecvQueue</activation-config-property-value> </activation-config-property> <activation-config-property> <activation-config-property-name>destinationType</activation-config-property-name> <activation-config-property-value>javax.jms.Queue</activation-config-property-value> </activation-config-property> </activation-config> </message-driven> </enterprise-beans> </openejb-jar>
geronimo-application.xml and application.xml define the main components of the EAR. Both EJB component and Web archive information are given in this files as usual.
<application xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.1"> <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1"> <dep:moduleId> <dep:groupId>samples</dep:groupId> <dep:artifactId>Order</dep:artifactId> <dep:version>1.0</dep:version> <dep:type>car</dep:type> </dep:moduleId> <dep:dependencies/> <dep:hidden-classes/> <dep:non-overridable-classes/> </dep:environment> </application>
<?xml version="1.0" encoding="UTF-8"?> <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" version="1.4"> <module> <ejb>OrderEjb.jar</ejb> </module> <module> <web> <web-uri>OrderWeb.war</web-uri> <context-root>/Order</context-root> </web> </module> </application>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <servlet> <display-name>OrderMgmtServlet</display-name> <servlet-name>OrderMgmtServlet</servlet-name> <servlet-class>org.apache.geronimo.samples.order.web.OrderMgmtServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>OrderMgmtServlet</servlet-name> <url-pattern>/order</url-pattern> </servlet-mapping> <resource-ref> <res-ref-name>jms/OrderRecvConnectionFactory</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <message-destination-ref> <message-destination-ref-name>jms/OrderRecvQueue</message-destination-ref-name> <message-destination-type>javax.jms.Queue</message-destination-type> <message-destination-usage>Produces</message-destination-usage> <message-destination-link>OrderRecvQueue</message-destination-link> </message-destination-ref> <welcome-file-list> <welcome-file>/jsp/index.jsp</welcome-file> </welcome-file-list> </web-app>
<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.1" xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.1"> <dep:environment xmlns:dep="http://geronimo.apache.org/xml/ns/deployment-1.1"> <dep:moduleId> <dep:groupId>samples</dep:groupId> <dep:artifactId>OrderWeb</dep:artifactId> <dep:version>1.0</dep:version> <dep:type>car</dep:type> </dep:moduleId> <dep:dependencies> <dep:dependency> <dep:groupId>geronimo</dep:groupId> <dep:artifactId>activemq-broker</dep:artifactId> <dep:version>1.1</dep:version> <dep:type>car</dep:type> </dep:dependency> <dep:dependency> <dep:groupId>samples</dep:groupId> <dep:artifactId>jms-resources</dep:artifactId> <dep:version>1.0</dep:version> <dep:type>rar</dep:type> </dep:dependency> </dep:dependencies> <dep:hidden-classes/> <dep:non-overridable-classes/> </dep:environment> <context-root>/Order</context-root> <resource-ref> <ref-name>jms/OrderRecvConnectionFactory</ref-name> <resource-link>OrderRecvConnectionFactory</resource-link> </resource-ref> <resource-env-ref> <ref-name>jms/OrderRecvQueue</ref-name> <admin-object-link>OrderRecvQueue</admin-object-link> </resource-env-ref> </web-app>
Tools used
The tools used for developing and building the Banking applications are:
XDoclet
XDoclet is an open source code generation engine. It enables Attribute-Oriented Programming for java. In short, this means that you can add more significance to your code by adding meta data (attributes) to your java sources. This is done in special JavaDoc tags.
Although XDoclet originated as a tool for creating EJBs, it has evolved into a general-purpose code generation engine. XDoclet consists of a core and a constantly growing number of modules. It is fairly straightforward to write new modules if there is a need for a new kind of component.
http://xdoclet.sourceforge.net/xdoclet/index.html
Eclipse
The Eclipse IDE was used for development of the sample application. This is a very powerful and popular open source development tool. It has integration plug-ins for the Geronimo too. Eclipse can be downloaded from the following URL:
http://www.eclipse.org
Apache Ant
Ant is a pure Java build tool. It is used for building the war files for the Inventory application. Ant can be downloaded from the following URL:
http://ant.apache.org
Configuring, Building and Deploying the Sample Application
Download the order processing application from the following link:
Order
After decompressing the given file, the Order directory is created.
Configuring
Configuration of the application consists of creating the database and defining the connection pool to access it.
Creating JMS Specific Resources
Modify Property Files
This build script depends on XDoclet version 1.2.3 and Geronimo 1.1.
Building
Deploying
Testing of the Sample Application
Order Placement Web Application
Order Placement Remote Application
Always consider lib folder inside of releases are a part of this client application.Check your Operating Sytem's security configuration when you are connecting from a remote machine.