Home > Store > Programming > Java

Java™ Message Service API Tutorial and Reference: Messaging for the J2EE™ Platform

Register your product to gain access to bonus material or receive a coupon.

Java™ Message Service API Tutorial and Reference: Messaging for the J2EE™ Platform

Book

  • Your Price: $39.99
  • List Price: $49.99
  • Available on demand.

Description

  • Copyright 2002
  • Dimensions: 7-3/8x9-1/4
  • Pages: 544
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-78472-6
  • ISBN-13: 978-0-201-78472-5

Java™ Message Service API Tutorial and Reference provides a clear and complete introduction to the Java™ Message Service (JMS) API. This book illustrates how to use the JMS API to build applications that create, send, receive, and read messages. Beginning with comprehensive descriptions of fundamental JMS concepts and building blocks, the coverage extends to all aspects of running and creating JMS applications. Each topic area is supported by relevant and well-crafted JMS program examples that demonstrate how to put the technology to work.

The JMS API is an integral part of the Java 2 Platform, Enterprise Edition (J2EE™ platform). Developed by Sun Microsystems in close cooperation with enterprise messaging partners, JMS works together with other technologies to provide reliable, asynchronous communication between components in a distributed computing environment. It delivers a new, powerful tool for enterprise messaging--the cornerstone of today's enterprise applications.

You will find in-depth coverage on how to:

  • Create and run JMS client programs
  • Use the JMS API within the J2EE platform
  • Consume messages asynchronously with a message-driven bean
  • Produce messages from an application client and from a session bean
  • Access an entity bean from a message-driven bean
  • Create applications for the J2EE platform that use the JMS API to
  • Consume messages Produce messages Access an entity bean

From BytesMessage to TransactionRolledBackException, a useful alphabetical reference provides complete information on all facets of the JMS API.

Additionally, the tutorial example programs are downloadable from the Sun Web site, so that you can adapt them to implementations of the JMS API and the J2EE platform.

Written by an expert team, the book offers an unparalleled technical understanding of JMS and its integration into the J2EE platform. Its thorough and practical coverage of JMS makes it easy for developers working in a distributed Java technology environment, and those familiar with the J2EE platform, to efficiently integrate the JMS API.



0201784726B02212002

Sample Content

Online Sample Chapter

Introduction to the JMS API Programming Model

Downloadable Sample Chapter

Click below for Sample Chapter related to this title:
hapnerch03.pdf

Table of Contents



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.
Index. 0201784726T0213200

Preface

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:

  • To introduce the JMS API to new users, with simple JMS client program examples
  • To show how to use the JMS API within the Java 2 Platform, Enterprise Edition (J2EE™ platform), with additional simple examples showing how to
  • Consume messages asynchronously with a message-driven bean
    Produce messages from an application client
    Produce messages from a session bean
    Access an entity bean from a message-driven bean
    Produce and consume messages on more than one system
    To provide a full reference to the JMS API for JMS client programmers

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.
  • Italic font is used for introducing new terms, for book titles, and for emphasis.

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.

0201784726P02132002

Index

A

acknowledge method (Message interface) 57, 286

acknowledging messages. See message acknowledgment

administered objects 16

J2EE applications and 68
See also connection factories, destinations

application clients

coding 77, 99, 126, 177
packaging 84, 111, 157, 191
running 94, 119, 172, 200, 208

Application Deployment Tool. See deploytool command

applications

client 27, 201, 429
J2EE 67, 75, 97, 123, 175

asynchronous message consumption 13

getMessageListener method (MessageConsumer interface) 311
MessageListener interface 319
setMessageListener method (MessageConsumer interface) 313
See also message-driven beans

authentication

createQueueConnection method (QueueConnectionFactory interface) 346
createTopicConnection method (TopicConnectionFactory interface) 402
JMSSecurityException class 257

AUTO_ACKNOWLEDGE mode

example 464
Session interface field 57, 370
B

bean-managed transactions 72

BytesMessage interface 25, 211

readBoolean method 213
readByte method 213
readBytes method 214
readChar method 215
readDouble method 216
readFloat method 216
readInt method 216
readLong method 217
readShort method 217
readUnsignedByte method 217
readUnsignedShort method 218
readUTF method 218
reset method 219
writeBoolean method 219
writeByte method 219
writeBytes method 220
writeChar method 221
writeDouble method 221
writeFloat method 221
writeInt method 222
writeLong method 222
writeObject method 222
writeShort method 223
writeUTF method 223
C

CLASSPATH environment variable 28

clearBody method (Message interface) 287

clearProperties method (Message interface) 287

client applications 27, 429

compiling 37, 48
running 38, 49
running on multiple systems 51

client applications (cont.)

running remotely 52

client ID, for durable subscriptions 61, 110

getClientID method (Connection interface) 228
InvalidClientIDException class 247
setClientID method (Connection interface) 229

CLIENT_ACKNOWLEDGE mode

example 464
Session interface field 57, 370

close method

Connection interface 227
MessageConsumer interface 310
MessageProducer interface 326
QueueBrowser interface 340
QueueRequestor class 350
Session interface 371
TopicRequestor class 410

Cloudscape database server

starting 157
stopping 173

commands

cloudscape 157, 173
deploytool 83, 109, 156, 189
j2ee 37, 50, 83, 95, 109, 121, 156, 173, 189, 201
j2eeadmin 17, 18, 95, 110, 121, 173, 189, 201
runclient 94, 119, 172, 200, 208

commit method (Session interface) 64, 371

connection factories

ConnectionFactory interface 233
creating 51, 110, 189
deleting 121, 201
introduction 17
QueueConnectionFactory interface 345
specifying for deployment 86, 88, 114, 116, 159, 162, 164, 166, 168, 192, 196
specifying for remote servers 51, 189
TopicConnectionFactory interface 401

Connection interface 225

close method 227
getClientID method 228
getExceptionListener method 228
getMetaData method 228
setClientID method 229
setExceptionListener method 230
start method 230
stop method 231

ConnectionFactory interface 233

ConnectionMetaData interface 235

getJMSMinorVersion method 236
getJMSProviderName method 236
getJMSVersion method 237
getJMSXPropertyNames method 237
getProviderMajorVersion method 237
getProviderMinorVersion method 238
getProviderVersion method 238

connections

close method (Connection interface) 227
Connection interface 225
ConnectionMetaData interface 235
createQueueConnection method (QueueConnectionFactory interface) 346
createTopicConnection method (TopicConnectionFactory interface) 402
introduction 18
managing in J2EE applications 68
QueueConnection interface 343
start method (Connection interface) 230
stop method (Connection interface) 231
TopicConnection interface 399

container, EJB 7

message-driven beans 69

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

connection factories 17, 51, 110, 189
J2EE applications 84, 111, 157
queues 18, 37, 83, 156
topics 18, 49, 110
D

DEFAULT_DELIVERY_MODE field (Message interface) 285

DEFAULT_PRIORITY field (Message interface) 286

DEFAULT_TIME_TO_LIVE field (Message interface) 286

delete method

TemporaryQueue interface 392
TemporaryTopic interface 394

deleting

connection factories 121, 201
queues 39
topics 50, 121

delivery modes

DEFAULT_DELIVERY_MODE field (Message interface) 285
getDeliveryMode method (MessageProducer interface) 327
getJMSDeliveryMode method (Message interface) 290
introduction 58
JMSDeliveryMode message header field 24
setDeliveryMode method (MessageProducer interface) 328
setJMSDeliveryMode method (Message interface) 301

DeliveryMode interface 58, 239

NON_PERSISTENT delivery mode 240
PERSISTENT delivery mode 240

deployment descriptors

creating and packaging 87
JMS API-related elements 91

deploytool command 83, 109, 156, 189

deploytool command

Descriptor Viewer 91
New Application Client Wizard 84, 111, 157, 191
New Enterprise Bean Wizard 87, 160, 163, 165, 194

Destination interface 241

destination-type deployment descriptor element 91

destinations

Destination interface 241
getJMSDestination method (Message interface) 291
introduction 18
InvalidDestinationException class 249
JMSDestination message header field 24
Queue interface 337
setJMSDestination method (Message interface) 302
specifying for deployment 86, 88, 115-116, 162, 164, 166, 193, 196
temporary 60
Topic interface 397
See also queues, temporary destinations, topics

di

Updates

Submit Errata

More Information

ONE MONTH ACCESS!

WITH PURCHASE


Get unlimited 30-day access to thousands of Books & Training Videos about technology, professional development and digital media If you continue your subscription after your 30-day trial, you can receive 30% off a monthly subscription to the Safari Library for up to 12 months.