background image

Writing Simple JMS Client Applications

<< JMS Exception Handling | Synchronous Receive Example >>
<< JMS Exception Handling | Synchronous Receive Example >>

Writing Simple JMS Client Applications

Writing Simple JMS Client Applications
This section shows how to create, package, and run simple JMS client programs packaged as
stand-alone application clients. These clients access a Java EE server. The clients demonstrate
the basic tasks that a JMS application must perform:
Creating a connection and a session
Creating message producers and consumers
Sending and receiving messages
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.
This section covers the following topics:
"A Simple Example of Synchronous Message Receives" on page 911
"A Simple Example of Asynchronous Message Consumption" on page 920
"A Simple Example of Browsing Messages in a Queue" on page 926
"Running JMS Client Programs on Multiple Systems" on page 931
Each example uses two programs: one that sends messages and one that receives them. You can
run the programs in NetBeans IDE or in two terminal windows.
When you write a JMS application to run in a Java EE application, you use many of the same
methods in much the same sequence as you do for a stand-alone application client. However,
there are some significant differences.
"Using the JMS API in a Java EE Application" on page 954
describes these differences, and
Chapter 32, "Java EE Examples Using the JMS API"
provides
examples that illustrate them.
The examples for this section are in the following directory:
tut-install/javaeetutorial5/examples/jms/simple/
The examples are in the following four subdirectories:
producer
synchconsumer
asynchconsumer
messagebrowser
A Simple Example of Synchronous Message Receives
This section describes the sending and receiving programs in an example that uses the receive
method to consume messages synchronously. This section then explains how to compile,
package, and run the programs using the Application Server.
Writing Simple JMS Client Applications
Chapter 31 · The Java Message Service API
911