OReilly - Java Message Service, 2e.pdf

(1991 KB) Pobierz
653113052 UNPDF
SECOND EDITION
Java Message Service
Mark Richards, Richard Monson-Haefel, and
David A. Chappell
Beijing Cambridge Farnham Köln Sebastopol Taipei Tokyo
653113052.026.png 653113052.027.png 653113052.028.png 653113052.029.png 653113052.001.png 653113052.002.png 653113052.003.png
Java Message Service, Second Edition
by Mark Richards, Richard Monson-Haefel, and David A. Chappell
Copyright © 2009 Mark Richards. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles ( http://my.safaribooksonline.com ). For more information, contact our
corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
Editors: Mike Loukides and Julie Steele
Production Editor: Sarah Schneider
Production Services: Appingo, Inc.
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Printing History:
May 2009:
Second Edition.
O’Reilly and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Java Message Service ,
Second Edition, the image of a passenger pigeon, and related trade dress are trademarks of O’Reilly
Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-0-596-52204-9
[C]
1242320347
653113052.004.png 653113052.005.png 653113052.006.png 653113052.007.png
 
Table of Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
1. Messaging Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
The Advantages of Messaging
3
Heterogeneous Integration
3
Reduce System Bottlenecks
3
Increase Scalability
4
Increase End User Productivity
4
Architecture Flexibility and Agility
5
Enterprise Messaging
5
Centralized Architectures
7
Decentralized Architectures
7
Hybrid Architectures
8
Centralized Architecture As a Model
8
Messaging Models
9
Point-to-Point
10
Publish-and-Subscribe
10
JMS API
11
Point-to-Point API
13
Publish-and-Subscribe API
14
Real-World Scenarios
14
Service-Oriented Architecture
15
Event-Driven Architecture
16
Heterogeneous Platform Integration
16
Enterprise Application Integration
17
Business-to-Business
17
Geographic Dispersion
18
Information Broadcasting
18
Building Dynamic Systems
18
RPC Versus Asynchronous Messaging
21
v
653113052.008.png 653113052.009.png 653113052.010.png 653113052.011.png 653113052.012.png 653113052.013.png
Tightly Coupled RPC
21
Enterprise Messaging
23
2. Developing a Simple Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
The Chat Application
25
Getting Started with the Chat Example
28
Examining the Source Code
30
Sessions and Threading
39
3. Anatomy of a JMS Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Headers
42
Automatically Assigned Headers
43
Developer-Assigned Headers
46
Properties
47
Application-Specific Properties
47
JMS-Defined Properties
49
Provider-Specific Properties
50
Message Types
50
Message
50
TextMessage
51
ObjectMessage
52
BytesMessage
53
StreamMessage
56
MapMessage
58
Read-Only Messages
60
Client-Acknowledged Messages
61
Interoperability and Portability of Messages
61
4. Point-to-Point Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Point-to-Point Overview
63
When to Use Point-to-Point Messaging
66
The QBorrower and QLender Application
67
Configuring and Running the Application
67
The QBorrower Class
69
The QLender Class
76
Message Correlation
81
Dynamic Versus Administered Queues
83
Load Balancing Using Multiple Receivers
84
Examining a Queue
85
5. Publish-and-Subscribe Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Publish-and-Subscribe Overview
87
When to Use Publish-and-Subscribe Messaging
89
vi | Table of Contents
653113052.014.png 653113052.015.png 653113052.016.png 653113052.017.png 653113052.018.png 653113052.019.png
The TBorrower and TLender Application
90
Configuring and Running the Application
90
The TLender Class
92
The TBorrower Class
96
Durable Versus Nondurable Subscribers
100
Dynamic Versus Administered Subscribers
101
Unsubscribing Dynamic Durable Subscribers
104
Temporary Topics
104
6. Message Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Message Selectors
109
Identifiers
110
Literals
111
Comparison Operators
111
Arithmetic Operators
113
Declaring a Message Selector
114
Message Selector Examples
116
Managing Claims in an HMO
116
Notification of Certain Bids on Inventory
116
Priority Handling
116
Stock Trade Order Auditing
117
Not Delivered Semantics
117
Design Considerations
118
7. Guaranteed Messaging and Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Guaranteed Messaging
125
Message Autonomy
126
Store-and-Forward Messaging
126
Message Acknowledgments and Failure Conditions
126
Message Acknowledgments
127
AUTO_ACKNOWLEDGE
127
DUPS_OK_ACKNOWLEDGE
132
CLIENT_ACKNOWLEDGE
132
Message Groups and Acknowledgment
133
Handling Redelivery of Messages in an Application
134
Message Groups Example
134
Message Grouping and Multiple Receivers
143
Transacted Messages
145
Creating and Using a JMS Transaction
147
Transacted Session Example
147
Distributed Transactions
150
Lost Connections
151
The ExceptionListener Example
152
Table of Contents | vii
653113052.020.png 653113052.021.png 653113052.022.png 653113052.023.png 653113052.024.png 653113052.025.png
Zgłoś jeśli naruszono regulamin