Java Reference
In-Depth Information
In a Java EE application, some of these tasks are performed, in whole or in part, by the
container. If you learn about these tasks, you will have a good basis for understanding how
a JMS application works on the Java EE platform.
Each example uses two clients: one that sends messages and one that receives them. You
can run the clients in NetBeans IDE or in two terminal windows.
When you write a JMS client to run in an enterprise bean application, you use many of the
same methods in much the same sequence as for an application client. However, there are
some significant differences. “ Using the JMS API in Java EE Applications on page 368
describes these differences, and this chapter provides examples that illustrate them.
The examples for this section are in the tut-install /examples/jms/simple/ direct-
ory, under the following four subdirectories:
producer
synchconsumer
asynchconsumer
messagebrowser
A Simple Example of Synchronous Message Receives
This section describes the sending and receiving clients in an example that uses the re-
ceive method to consume messages synchronously. This section then explains how to
compile, package, and run the clients using the GlassFish Server.
The following subsections describe the steps in creating and running the example.
Writing the Clients for the Synchronous Receive Example
The sending client, producer/src/java/Producer.java , performs the follow-
ing steps:
1. Injects resources for a connection factory, queue, and topic:
Click here to view code image
@Resource(lookup = "jms/ConnectionFactory")
private static ConnectionFactory connectionFactory;
@Resource(lookup = "jms/Queue")private static Queue queue;
@Resource(lookup = "jms/Topic")private static Topic topic;
2. Retrieves and verifies command-line arguments that specify the destination type
and the number of arguments:
Search WWH ::




Custom Search