...
For example, the below XML content is the deployment descriptor (ejb-jar.xml
) of a stateless session bean that connects to a back end DB2 database.
Code Block |
---|
title | ejb-jar.xmlborderStyle=xml |
---|
borderStyle | solid |
---|
|
<?xml version="1.0" encoding="UTF-8" ?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
<description>Stateless Session Bean Example</description>
<display-name>Stateless Session Bean Example</display-name>
<enterprise-beans>
<session>
<ejb-name>RetrieveEmployeeInfoBean</ejb-name>
<business-remote>examples.session.stateless_dd.RetrieveEmployeeInfo</business-remote>
<ejb-class>examples.session.stateless_dd.RetrieveEmployeeInfoBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<resource-ref>
<res-ref-name>jdbc/DataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
</enterprise-beans>
<interceptors>
<interceptor>
<interceptor-class>
examples.session.stateless_dd.RetrieveEmployeeInfoCallbacks
</interceptor-class>
<post-construct>
<lifecycle-callback-method>construct</lifecycle-callback-method>
</post-construct>
<post-activate>
<lifecycle-callback-method>activate</lifecycle-callback-method>
</post-activate>
<pre-passivate>
<lifecycle-callback-method>passivate</lifecycle-callback-method>
</pre-passivate>
</interceptor>
</interceptors>
<assembly-descriptor>
<interceptor-binding>
<ejb-name>RetrieveEmployeeInfoBean</ejb-name>
<interceptor-class>
examples.session.stateless_dd.RetrieveEmployeeInfoCallbacks
</interceptor-class>
</interceptor-binding>
</assembly-descriptor>
</ejb-jar>
|
...
Code Block |
---|
title | openejb-jar.xmlborderStyle=xml |
---|
borderStyle | solid |
---|
|
<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
<sys:environment>
<sys:moduleId>
<sys:groupId>samples</sys:groupId>
<sys:artifactId>EmployeeDemo-ejb-dd</sys:artifactId>
<sys:version>3.0</sys:version>
<sys:type>jar</sys:type>
</sys:moduleId>
<sys:dependencies>
<sys:dependency>
<sys:groupId>console.dbpool</sys:groupId>
<sys:artifactId>jdbc/FEmployeeDatasource</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>rar</sys:type>
</sys:dependency>
</sys:dependencies>
</sys:environment>
<enterprise-beans>
<session>
<ejb-name>RetrieveEmployeeInfoBean</ejb-name>
<naming:resource-ref>
<naming:ref-name>jdbc/DataSource</naming:ref-name>
<naming:resource-link>jdbc/EmployeeDatasource</naming:resource-link>
</naming:resource-ref>
</session>
</enterprise-beans>
</openejb-jar>
|
...
Apache geronimo ships with ActiveMQ message broker and an inbound and outbound JMS resource adapter for the ActiveMQ broker. This sample illustrates deploying and running two MDBs that listen to a jms topic TextTopic
. When the web client publishes a message to this topic, the two MDBs receive the message and process it. Because the message is published to the topic, all the configured listeners, in this case the two MDBs, receive a copy of the message. In addition to that, we will also illustrate how to deploy a JMS resource adapter within the application scope. Usually, the resource adapters are deployed at the server scope and can be used by all other applications as well. In this example, a JMS resource plan is embedded in the application deployment plan geronimo-application.xml
and deployed while deploying the application archive.
Code Block |
---|
XML | XML |
---|
borderStyle | solid |
---|
title | ejb-jar.xml |
---|
|
<?xml version="1.0" encoding="UTF-8" ?>
<ejb-jar>
<enterprise-beans>
<message-driven>
<ejb-name>TextMessageBean1</ejb-name>
<ejb-class>
sample.mdb.TextMessageBean1
</ejb-class>
<messaging-type>
javax.jms.MessageListener
</messaging-type>
<transaction-type>Bean</transaction-type>
<message-destination-type>
javax.jms.Topic
</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>
destinationType
</activation-config-property-name>
<activation-config-property-value>
javax.jms.Topic
</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
<message-driven>
<ejb-name>TextMessageBean2</ejb-name>
<ejb-class>
sample.mdb.TextMessageBean2
</ejb-class>
<messaging-type>
javax.jms.MessageListener
</messaging-type>
<transaction-type>Bean</transaction-type>
<message-destination-type>
javax.jms.Topic
</message-destination-type>
<activation-config>
<activation-config-property>
<activation-config-property-name>
destinationType
</activation-config-property-name>
<activation-config-property-value>
javax.jms.Topic
</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</ejb-jar>
|
The ejb-jar.xml
declares the two MDBs sample.mdb.TextMessageBean1
and sample.mdb.TextMessageBean2
both listen to a javax.jms.Topic destination.
Code Block |
---|
XML | XML |
---|
borderStyle | solid |
---|
title | openejb-jar.xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
<sys:environment>
<sys:moduleId>
<sys:groupId>Sample</sys:groupId>
<sys:artifactId>MDB-EJB</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
</sys:environment>
<enterprise-beans>
<message-driven>
<ejb-name>
TextMessageBean1
</ejb-name>
<nam:resource-adapter>
<nam:resource-link>
TradeJMSResources
</nam:resource-link>
</nam:resource-adapter>
<activation-config>
<activation-config-property>
<activation-config-property-name>
destination
</activation-config-property-name>
<activation-config-property-value>
TextMessageTopic
</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.Topic</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
<message-driven>
<ejb-name>TextMessageBean2</ejb-name>
<nam:resource-adapter>
<nam:resource-link>
TradeJMSResources
</nam:resource-link>
</nam:resource-adapter>
<activation-config>
<activation-config-property>
<activation-config-property-name>
destination
</activation-config-property-name>
<activation-config-property-value>
TextMessageTopic
</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.Topic
</activation-config-property-value>
</activation-config-property>
</activation-config>
</message-driven>
</enterprise-beans>
</openejb-jar>
|
...
The web client for the application is as follows.
Code Block |
---|
XML | XML |
---|
borderStyle | solid |
---|
title | web.xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>MDBSampleWEB</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Test</display-name>
<servlet-name>Test</servlet-name>
<servlet-class>sample.mdb.Test</servlet-class>
</servlet>
<resource-ref>
<description>jms broker</description>
<res-ref-name>jms/broker</res-ref-name>
<res-type>
javax.jms.TopicConnectionFactory
</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-env-ref>
<description>Predefined Topic</description>
<resource-env-ref-name>
jms/Topic/TextTopic
</resource-env-ref-name>
<resource-env-ref-type>
javax.jms.Topic</resource-env-ref-type>
</resource-env-ref>
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
</web-app>
|
The web client declares the javax.jms.TopicConnectionFactory
and the topic to which the servlet has to publish the message. The names declared here are mapped to actual resources in the geronimo-web.xml
as follows.
Code Block |
---|
XML | XML |
---|
borderStyle | solid |
---|
title | geronimo-web.xml |
---|
|
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0"
xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
<sys:environment>
<sys:moduleId>
<sys:groupId>sample</sys:groupId>
<sys:artifactId>MDB-Web</sys:artifactId>
<sys:version>1.0</sys:version>
<sys:type>car</sys:type>
</sys:moduleId>
</sys:environment>
<context-root>/MDBSampleWEB</context-root>
<nam:resource-ref>
<nam:ref-name>
jms/broker</nam:ref-name>
<nam:resource-link>
jms/TopicConnectionFactory
</nam:resource-link>
</nam:resource-ref>
<nam:resource-env-ref>
<nam:ref-name>
jms/Topic/TextTopic
</nam:ref-name>
<nam:message-destination-link>
TextMessageTopic
</nam:message-destination-link>
</nam:resource-env-ref>
</web-app>
|
Please note that the jms/TopicConnectionFactory
and jms/Topic/TextTopic
are the names of the actual connection factory and jms topic. These are deployed by a jms resource plan embedded in the EAR's deployment plan as follows.
Code Block |
---|
XML | XML |
---|
borderStyle | solid |
---|
title | application.xml |
---|
|
<?xml version="1.0" encoding="ASCII"?>
<application
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns=http://java.sun.com/xml/ns/javaee
xmlns:app="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/application_5.xsd"
version="5">
<display-name>MDBSampleEAR</display-name>
<module>
<ejb>MDBSampleEJB.jar</ejb>
</module>
<module>
<web>
<web-uri>MDBSampleWEB.war</web-uri>
<context-root>MDBSampleWEB</context-root>
</web>
</module>
</application>
|
...