HAPPY BOOKSGIVING
Use code BOOKSGIVING during checkout to save 40%-55% on books and eBooks. Shop now.
Register your product to gain access to bonus material or receive a coupon.
Java Message Service (JMS) represents a powerful solution for communicating between Java enterprise applications, software components, and legacy systems. In this authoritative tutorial and comprehensive reference, Sun's Java Message Service architects offer start-to-finish coverage of peer-to-peer JMS development with Java 2 Platform, Enterprise Edition, Release 1.3. JMS is now fully integrated into the J2EE platform -- and this is the first book to show how to make the most of JMS in the context of sophisticated J2EE application development. The authors begin by introducing the JMS API to developers who are new to it. Then, with the help of extensive programming examples, they demonstrate key JMS techniques for enabling applications to create, send, receive, and read messages, and for integrating with existing back office and enterprise systems. Coverage includes: consuming messages asynchronously with message-driven beans; producing messages from application clients; accessing entity beans from message-driven bean; producing messages from session beans; and much more. For all Java developers building applications that must communicate and share information.
Introduction to the JMS API Programming Model
Click below for Sample Chapter related to this title:
hapnerch03.pdf
Preface.
Acknowledgments.
I. OVERVIEW.
1. Overview.What Is Messaging?
What Is the JMS API?
When Can You Use the JMS API?
How Does the JMS API Work with the J2EE™ Platform?
2. Basic JMS API Concepts.JMS API Architecture.
Messaging Domains.
Point-to-Point Messaging Domain.
Publish/Subscribe Messaging Domain.
Message Consumption.
3. The JMS API Programming Model.Administered Objects.
Connection Factories.
Destinations.
Connections.
Sessions.
Message Producers.
Message Consumers.
Message Listeners.
Message Selectors.
Messages.
Message Headers.
Message Properties.
Message Bodies.
Exception Handling.
4. Writing Simple JMS Client Applications.Setting Your Environment for Running Applications.
A Simple Point-to-Point Example.
Writing the PTP Client Programs.
Compiling the PTP Clients.
Starting the JMS Provider.
Creating the JMS Administered Objects.
Running the PTP Clients.
Deleting the Queue.
A Simple Publish/Subscribe Example.
Writing the Pub/Sub Client Programs.
Compiling the Pub/Sub Clients.
Starting the JMS Provider.
Creating the JMS Administered Objects.
Running the Pub/Sub Clients.
Deleting the Topic and Stopping the Server.
Running JMS Client Programs on Multiple Systems.
Communicating Between Two J2EE Servers.
Communicating Between a J2EE Server and a System Not Running a J2EE Server.
5. Creating Robust JMS Applications.Using Basic Reliability Mechanisms.
Controlling Message Acknowledgment.
Specifying Message Persistence.
Setting Message Priority Levels.
Allowing Messages to Expire.
Creating Temporary Destinations.
Using Advanced Reliability Mechanisms.
Creating Durable Subscriptions.
Using JMS API Local Transactions.
6. Using the JMS API in a J2EE Application.Using Enterprise Beans to Produce and Synchronously Receive Messages.
Administered Objects.
Resource Management.
Transactions.
Using Message-Driven Beans.
Managing Distributed Transactions.
Using the JMS API with Application Clients and Web Components.
7. A Simple J2EE Application that Uses the JMS API.Writing and Compiling the Application Components.
Coding the Application Client: SimpleClient.java.
Coding the Message-Driven Bean: MessageBean.java.
Compiling the Source Files.
Creating and Packaging the Application.
Starting the J2EE Server and Deploytool.
Creating a Queue.
Creating the J2EE Application.
Packaging the Application Client.
Packaging the Message-Driven Bean.
Checking the JNDI Names.
Deploying and Running the Application.
Looking at the Deployment Descriptor.
Adding the Server.
Deploying the Application.
Running the Client.
Undeploying the Application.
Removing the Application and Stopping the Server.
8. A J2EE Application that Uses the JMS API with a Session Bean.Writing and Compiling the Application Components.
Coding the Application Client: MyAppClient.java.
Coding the Publisher Session Bean.
Coding the Message-Driven Bean: MessageBean.java.
Compiling the Source Files.
Creating and Packaging the Application.
Starting the J2EE Server and Deploytool.
Creating a Topic.
Creating a Connection Factory.
Creating the J2EE Application.
Packaging the Application Client.
Packaging the Session Bean.
Packaging the Message-Driven Bean.
Specifying the JNDI Names.
Deploying and Running the Application.
Adding the Server.
Deploying the Application.
Running the Client.
Undeploying the Application.
Removing the Application and Stopping the Server.
9. A J2EE Application that Uses the JMS API with an Entity Bean.Overview of the Human Resources Application.
Writing and Compiling the Application Components.
Coding the Application Client: HumanResourceClient.java.
Coding the Message-Driven Beans.
Coding the Entity Bean.
Compiling the Source Files.
Creating and Packaging the Application.
Starting the J2EE Server and Deploytool.
Creating a Queue.
Starting the Cloudscape Database Server.
Creating the J2EE Application.
Packaging the Application Client.
Packaging the Equipment Message-Driven Bean.
Packaging the Office Message-Driven Bean.
Packaging the Schedule Message-Driven Bean.
Packaging the Entity Bean.
Specifying the Entity Bean Deployment Settings.
Specifying the JNDI Names.
Deploying and Running the Application.
Adding the Server.
Deploying the Application.
Running the Client.
Undeploying the Application.
Removing the Application and Stopping the Server.
10. An Application Example that Uses Two J2EE Servers.Overview of the Applications.
Writing and Compiling the Application Components.
Coding the Application Client: MultiAppServerRequester.java.
Coding the Message-Driven Bean: ReplyMsgBean.java.
Compiling the Source Files.
Creating and Packaging the Application.
Starting the J2EE Servers and Deploytool.
Creating a Connection Factory.
Creating the First J2EE Application.
Packaging the Application Client.
Creating the Second J2EE Application.
Packaging the Message-Driven Bean.
Checking the JNDI Names.
Deploying and Running the Applications.
Adding the Server.
Deploying the Applications.
Running the Client.
Undeploying the Applications.
Removing the Applications and Stopping the Servers.
Accessing a J2EE Application from a Remote System That Is Not Running a J2EE Server.
Accessing a J2EE Application from a Standalone Client.
Using runclient to Access a Remote Application Client.
II. BYTESMESSAGE.
11. BytesMessage.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
12. Connection.Overview and Related Interfaces.
Interface Definition.
Methods.
13. ConnectionFactory.Overview and Related Interfaces.
Interface Definition.
14. ConnectionMetaData.Overview.
Interface Definition.
Methods.
15. DeliveryMode.Overview.
Interface Definition.
Fields.
16. Destination.Overview and Related Interfaces.
Interface Definition.
17. ExceptionListener.Overview and Related Method.
Interface Definition.
Methods.
18. IllegalStateException.Overview.
Class Definition.
Constructors.
19. InvalidClientIDException.Overview.
Class Definition.
Constructors.
20. InvalidDestinationException.Overview.
Class Definition.
Constructors.
21. InvalidSelectorException.Overview.
Class Definition.
Constructors.
22. JMSException.Overview.
Class Definition.
Constructors.
Methods.
23. JMSSecurityException.Overview.
Class Definition.
Constructors.
24. MapMessage.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
25. Message.Overview.
Message Bodies.
Message Headers.
Message Properties.
Provider Implementations of JMS Message Interfaces.
Message Selectors.
Related Methods and Interfaces.
Interface Definition.
Fields.
Methods
26. MessageConsumer.Overview and Related Interfaces.
Interface Definition.
Methods.
27. MessageEOFException.Overview.
Class Definition.
Constructors.
28. MessageFormatException.Overview.
Class Definition.
Constructors.
29. MessageListener.Overview.
Interface Definition.
Methods.
30. MessageNotReadableException.Overview.
Class Definition.
Constructors.
31. MessageNotWriteableException.Overview.
Class Definition.
Constructors.
32. MessageProducer.Overview and Related and Interfaces.
Interface Definition.
Methods.
33. ObjectMessage.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
34. Queue.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
35. QueueBrowser.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
36. QueueConnection.Overview and Related Interfaces.
Interface Definition.
Methods.
37. QueueConnectionFactory.Overview and Related Interfaces.
Interface Definition.
Methods.
38. QueueReceiver.Overview and Related Interfaces.
Interface Definition.
Methods.
39. QueueRequestor.Overview and Related Interfaces.
Class Definition.
Constructor.
Methods.
40. QueueSender.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
41. QueueSession.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
42. ResourceAllocationException.Overview.
Class Definition.
Constructors.
43. Session.Overview and Related Interfaces.
Interface Definition.
Fields.
Methods.
44. StreamMessage.Overview and Related Methods and Interfaces.
Interface Definition.
Method.
45. TemporaryQueue.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
46. TemporaryTopic.Overview and Related Methods and Interfaces.
Interface Definition.
Methods. @CHAPTER 47. TextMessage.
Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
48. Topic.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
49. TopicConnection.Overview and Related Interfaces.
Interface Definition.
Methods.
50. TopicConnectionFactory.Overview and Related Interfaces.
Interface Definition.
Methods.
51. TopicPublisher.Overview and Related Method.
Interface Definition.
Methods.
52. TopicRequestor.Overview and Related Interface.
Class Definition.
Constructor.
Methods.
53. TopicSession.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
54. TopicSubscriber.Overview and Related Methods and Interfaces.
Interface Definition.
Methods.
55. TransactionInProgressException.Overview.
Class Definition.
Constructors.
56. TransactionRolledBackException.Overview.
Class Definition.
Constructors.
Appendix A: JMS Client Examples.Durable Subscriptions.
Transactions.
Acknowledgment Modes.
Utility Class.
Glossary.The Java Message Service Tutorial and Reference provides an introduction to the Java Message Service (JMS) API for new users. It has the following goals:
The audience for this book is programmers who expect to write JMS applications, especially applications for the J2EE platform ("J2EE applications") that use the JMS API. We assume that you are familiar with the Java programming language and that you have some experience with earlier versions of the J2EE platform.
In order to run the tutorial examples, we recommend that you download and install the Java 2 Software Development Kit, Enterprise Edition (J2EE SDK), version 1.3 or above, which is available at no charge and runs on the Solaris Operating Environment and on the Linux and Windows NT/2000 operating systems. See http://java.sun.com/j2ee/ for more information and a link to the J2EE SDK. You should first install the required version of the Java 2 Software Development Kit, Standard Edition (J2SE SDK), if it is not already installed.
You can download the examples in this book, along with an HTML version of the tutorial, from the following location: http://java.sun.com/products/jms/tutorial/. The downloaded examples are in a directory named jms_tutorial/examples (on UNIX(R) systems) or jms_tutorial\examples (on Microsoft Windows systems).
You may adapt the examples to other implementations of the JMS API and the J2EE platform, but you will need to study your vendor's documentation to determine how to modify the parts of the examples and instructions that deal with external resources, such as JMS administered objects (connection factories and destinations) and databases. For the J2EE platform examples, you will also need to adapt the instructions to use your vendor's packaging and deployment tools.
Part Two, the reference, is based on the API documentation for JMS version 1.0.2b. The reference describes all parts of the API that apply to JMS application programmers. It does not describe the methods and interfaces that are used only for implementing a JMS provider.
This book uses a few simple documentation conventions:
Monospace font
is used for code, which includes what would be typed in a source code file or on the command line, URLs, file names, keywords, and names of classes, interfaces, exceptions, constructors, methods, and fields.Italic code font
is used for variables in text, command lines, and method explanations.We welcome your comments, questions, and suggestions. Please send them to the following e-mail address: jms-book@sun.com.
Errata for this book and information on other books in the Addison-Wesley Java series will be posted at http://java.sun.com/Series.A
acknowledge method (Message interface) 57, 286
acknowledging messages. See message acknowledgment
administered objects 16
application clients
Application Deployment Tool. See deploytool command
applications
asynchronous message consumption 13
authentication
AUTO_ACKNOWLEDGE mode
bean-managed transactions 72
BytesMessage interface 25, 211
CLASSPATH environment variable 28
clearBody method (Message interface) 287
clearProperties method (Message interface) 287
client applications 27, 429
client applications (cont.)
client ID, for durable subscriptions 61, 110
CLIENT_ACKNOWLEDGE mode
close method
Cloudscape database server
commands
commit method (Session interface) 64, 371
connection factories
Connection interface 225
ConnectionFactory interface 233
ConnectionMetaData interface 235
connections
container, EJB 7
container-managed transactions 72, 88
createBrowser method (QueueSession interface) 360
createBytesMessage method (Session interface) 372
createDurableSubscriber method (TopicSession interface) 414-415
createMapMessage method (Session interface) 372
createMessage method (Session interface) 372
createObjectMessage method (Session interface) 373
createPublisher method (TopicSession interface) 416
createQueue method (QueueSession interface) 361
createQueueConnection method (QueueConnectionFactory interface) 346
createQueueSession method (QueueConnection interface) 344
createReceiver method (QueueSession interface) 361-362
createSender method (QueueSession interface) 362
createStreamMessage method (Session interface) 373
createSubscriber method (TopicSession interface) 416-417
createTemporaryQueue method (QueueSession interface) 362
createTemporaryTopic method (TopicSession interface) 418
createTextMessage method (Session interface) 373-374
createTopic method (TopicSession interface) 418
createTopicConnection method (TopicConnectionFactory interface) 402
createTopicSession method (TopicConnection interface) 400
creating
DEFAULT_DELIVERY_MODE field (Message interface) 285
DEFAULT_PRIORITY field (Message interface) 286
DEFAULT_TIME_TO_LIVE field (Message interface) 286
delete method
deleting
delivery modes
DeliveryMode interface 58, 239
deployment descriptors
deploytool command 83, 109, 156, 189
deploytool command
Destination interface 241
destination-type deployment descriptor element 91
destinations
di