background image

Using the JMS API

<< The transactedexample JAR | Produce and Synchronously Receive Messages >>
<< The transactedexample JAR | Produce and Synchronously Receive Messages >>

Using the JMS API

After you run the program, you can delete the physical destinations and the destination
resources. Go to the directory
tut-install/javaeetutorial5/examples/jms/advanced/transactedexample/ and type the
following command:
ant delete-resources
Use the following command to remove the class and JAR files:
ant clean
Using the JMS API in a Java EE Application
This section describes the ways in which using the JMS API in a Java EE application differs from
using it in a stand-alone client application:
"Using @Resource Annotations in Java EE Components" on page 954
"Using Session Beans to Produce and to Synchronously Receive Messages" on page 955
"Using Message-Driven Beans to Receive Messages Asynchronously" on page 956
"Managing Distributed Transactions" on page 958
"Using the JMS API with Application Clients and Web Components" on page 960
A general rule in the Java EE platform specification applies to all Java EE components that use
the JMS API within EJB or web containers:
Application components in the web and EJB containers must not attempt to create more than
one active (not closed) Session object per connection.
This rule does not apply to application clients.
Using @Resource Annotations in Java EE Components
When you use the @Resource annotation in an application client component, you normally
declare the JMS resource static:
@Resource(mappedName=
"jms/ConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(mappedName=
"jms/Queue")
private static Queue queue;
However, when you use this annotation in a session bean, a message-driven bean, or a web
component, do not declare the resource static:
Using the JMS API in a Java EE Application
The Java EE 5 Tutorial · September 2007
954