logo资料库

Enterprise Integration Patterns.pdf

第1页 / 共574页
第2页 / 共574页
第3页 / 共574页
第4页 / 共574页
第5页 / 共574页
第6页 / 共574页
第7页 / 共574页
第8页 / 共574页
资料共574页,剩余部分请下载后查看
Table of Content
Foreword
Foreword
Preface
Who Should Read This Book
What You Will Learn
What This Book Does Not Cover
How This Book Is Organized
Acknowledgements
About the Cover Picture
Introduction
What is Messaging?
What is a Messaging System?
Why Use Messaging?
Challenges of Asynchronous Messaging
Thinking Asynchronously
Distributed Applications vs. Integration
Commercial Messaging Systems
Pattern Form
Diagram Notation
Examples and Interludes
Organization of this Book
Getting Started
Supporting Web Site
Summary
1 Solving Integration Problems using Patterns
The Need for Integration
Integration Challenges
How Integration Patterns Can Help
The Wide World of Integration
Loose Coupling
1 Minute EAI
A Loosely Coupled Integration Solution
Widget- Gadget Corp -- An Example
Summary
2 Integration Styles
Introduction
Application Integration Criteria
Application Integration Options
File Transfer
Shared Database
Remote Procedure Invocation
Messaging
3 Messaging Systems
Introduction
Message Channel
Message
Pipes and Filters
Message Router
Message Translator
Message Endpoint
4 Messaging Channels
Introduction
Point- to- Point Channel
Publish- Subscribe Channel
Datatype Channel
Invalid Message Channel
Dead Letter Channel
Guaranteed Delivery
Channel Adapter
Messaging Bridge
Message Bus
5 Message Construction
Introduction
Command Message
Document Message
Event Message
Request- Reply
Return Address
Correlation Identifier
Message Sequence
Message Expiration
Format Indicator
6 Interlude Simple Messaging
Introduction
JMS Request/ Reply Example
.NET Request/ Reply Example
JMS Publish/ Subscribe Example
7 Message Routing
Introduction
Content- Based Router
Message Filter
Dynamic Router
Recipient List
Splitter
Aggregator
Resequencer
Composed Message Processor
Scatter- Gather
Routing Slip
Process Manager
Message Broker
8 Message Transformation
Introduction
Envelope Wrapper
Content Enricher
Content Filter
Claim Check
Normalizer
Canonical Data Model
9 Interlude Composed Messaging
Introduction
Synchronous Implementation using Web Services
Asynchronous Implementation with MSMQ
Asynchronous Implementation with TIBCO
ActiveEnterprise
10 Messaging Endpoints
Introduction
Messaging Gateway
Messaging Mapper
Transactional Client
Polling Consumer
Event- Driven Consumer
Competing Consumers
Message Dispatcher
Selective Consumer
Durable Subscriber
Idempotent Receiver
Service Activator
11 System Management
Introduction
Control Bus
Detour
Wire Tap
Message History
Message Store
Smart Proxy
Test Message
Channel Purger
12 Interlude System Management Example
Loan Broker System Management
13 Integration Patterns in Practice
Case Study: Bond Trading System
Architecture with Patterns
14 Concluding Remarks
Emerging Standards and Futures in Enterprise
Integration
Bibliography
Table of Content TABLE OF CONTENT ........................................................................................................................................ 2 FOREWORD......................................................................................................................................................... 6 FOREWORD......................................................................................................................................................... 7 PREFACE.............................................................................................................................................................. 8 WHO SHOULD READ THIS BOOK ......................................................................................................................... 8 WHAT YOU WILL LEARN ..................................................................................................................................... 9 WHAT THIS BOOK DOES NOT COVER .................................................................................................................. 9 HOW THIS BOOK IS ORGANIZED........................................................................................................................ 10 ACKNOWLEDGEMENTS .......................................................................................................................................11 ABOUT THE COVER PICTURE ..............................................................................................................................11 INTRODUCTION............................................................................................................................................... 12 WHAT IS MESSAGING?....................................................................................................................................... 13 WHAT IS A MESSAGING SYSTEM? ...................................................................................................................... 14 WHY USE MESSAGING?..................................................................................................................................... 15 CHALLENGES OF ASYNCHRONOUS MESSAGING................................................................................................. 18 THINKING ASYNCHRONOUSLY........................................................................................................................... 19 DISTRIBUTED APPLICATIONS VS. INTEGRATION ................................................................................................. 19 COMMERCIAL MESSAGING SYSTEMS................................................................................................................. 20 PATTERN FORM.................................................................................................................................................. 22 DIAGRAM NOTATION ......................................................................................................................................... 24 EXAMPLES AND INTERLUDES............................................................................................................................. 25 ORGANIZATION OF THIS BOOK........................................................................................................................... 26 GETTING STARTED............................................................................................................................................. 27 SUPPORTING WEB SITE...................................................................................................................................... 29 SUMMARY.......................................................................................................................................................... 29 1.SOLVING INTEGRATION PROBLEMS USING PATTERNS............................................................... 31 THE NEED FOR INTEGRATION............................................................................................................................. 31 INTEGRATION CHALLENGES............................................................................................................................... 32 HOW INTEGRATION PATTERNS CAN HELP.......................................................................................................... 33 THE WIDE WORLD OF INTEGRATION.................................................................................................................. 34 LOOSE COUPLING .............................................................................................................................................. 37 1 MINUTE EAI................................................................................................................................................... 39 A LOOSELY COUPLED INTEGRATION SOLUTION................................................................................................. 42 WIDGET-GADGET CORP -- AN EXAMPLE ........................................................................................................... 44 SUMMARY.......................................................................................................................................................... 61 2.INTEGRATION STYLES............................................................................................................................ 63
INTRODUCTION.................................................................................................................................................. 63 APPLICATION INTEGRATION CRITERIA............................................................................................................... 63 APPLICATION INTEGRATION OPTIONS ................................................................................................................ 64 FILE TRANSFER.................................................................................................................................................. 65 SHARED DATABASE ........................................................................................................................................... 68 REMOTE PROCEDURE INVOCATION.................................................................................................................... 70 MESSAGING....................................................................................................................................................... 72 3.MESSAGING SYSTEMS............................................................................................................................. 75 INTRODUCTION.................................................................................................................................................. 75 MESSAGE CHANNEL .......................................................................................................................................... 76 MESSAGE........................................................................................................................................................... 81 PIPES AND FILTERS ............................................................................................................................................ 84 MESSAGE ROUTER............................................................................................................................................. 91 MESSAGE TRANSLATOR..................................................................................................................................... 96 MESSAGE ENDPOINT........................................................................................................................................ 105 4.MESSAGING CHANNELS ....................................................................................................................... 108 INTRODUCTION................................................................................................................................................ 108 POINT-TO-POINT CHANNEL...............................................................................................................................111 PUBLISH-SUBSCRIBE CHANNEL........................................................................................................................113 DATATYPE CHANNEL ........................................................................................................................................116 INVALID MESSAGE CHANNEL ...........................................................................................................................119 DEAD LETTER CHANNEL ................................................................................................................................. 122 GUARANTEED DELIVERY................................................................................................................................. 124 CHANNEL ADAPTER......................................................................................................................................... 128 MESSAGING BRIDGE........................................................................................................................................ 132 MESSAGE BUS ................................................................................................................................................. 135 5.MESSAGE CONSTRUCTION.................................................................................................................. 140 INTRODUCTION................................................................................................................................................ 140 COMMAND MESSAGE ...................................................................................................................................... 141 DOCUMENT MESSAGE ..................................................................................................................................... 143 EVENT MESSAGE ............................................................................................................................................. 145 REQUEST-REPLY .............................................................................................................................................. 147 RETURN ADDRESS ........................................................................................................................................... 151 CORRELATION IDENTIFIER ............................................................................................................................... 154 MESSAGE SEQUENCE....................................................................................................................................... 159 MESSAGE EXPIRATION..................................................................................................................................... 164 FORMAT INDICATOR......................................................................................................................................... 167 6.INTERLUDE:SIMPLE MESSAGING .................................................................................................. 169 INTRODUCTION................................................................................................................................................ 169 JMS REQUEST/REPLY EXAMPLE...................................................................................................................... 171 .NET REQUEST/REPLY EXAMPLE .................................................................................................................... 182
JMS PUBLISH/SUBSCRIBE EXAMPLE ............................................................................................................... 191 7.MESSAGE ROUTING............................................................................................................................... 208 INTRODUCTION................................................................................................................................................ 208 CONTENT-BASED ROUTER................................................................................................................................211 MESSAGE FILTER............................................................................................................................................. 217 DYNAMIC ROUTER .......................................................................................................................................... 221 RECIPIENT LIST................................................................................................................................................ 226 SPLITTER ......................................................................................................................................................... 234 AGGREGATOR .................................................................................................................................................. 242 RESEQUENCER................................................................................................................................................. 255 COMPOSED MESSAGE PROCESSOR................................................................................................................... 265 SCATTER-GATHER............................................................................................................................................ 267 ROUTING SLIP.................................................................................................................................................. 270 PROCESS MANAGER ........................................................................................................................................ 278 MESSAGE BROKER .......................................................................................................................................... 286 8.MESSAGE TRANSFORMATION............................................................................................................ 291 INTRODUCTION................................................................................................................................................ 291 ENVELOPE WRAPPER....................................................................................................................................... 292 CONTENT ENRICHER........................................................................................................................................ 297 CONTENT FILTER ............................................................................................................................................. 302 CLAIM CHECK ................................................................................................................................................. 305 NORMALIZER................................................................................................................................................... 310 CANONICAL DATA MODEL............................................................................................................................... 312 9.INTERLUDE:COMPOSED MESSAGING........................................................................................... 317 INTRODUCTION................................................................................................................................................ 317 SYNCHRONOUS IMPLEMENTATION USING WEB SERVICES ................................................................................ 324 ASYNCHRONOUS IMPLEMENTATION WITH MSMQ........................................................................................... 353 ASYNCHRONOUS IMPLEMENTATION WITH TIBCO ACTIVEENTERPRISE........................................................... 397 10.MESSAGING ENDPOINTS .................................................................................................................... 415 INTRODUCTION................................................................................................................................................ 415 MESSAGING GATEWAY..................................................................................................................................... 418 MESSAGING MAPPER....................................................................................................................................... 426 TRANSACTIONAL CLIENT................................................................................................................................. 431 POLLING CONSUMER ....................................................................................................................................... 439 EVENT-DRIVEN CONSUMER............................................................................................................................. 442 COMPETING CONSUMERS ................................................................................................................................ 446 MESSAGE DISPATCHER .................................................................................................................................... 451 SELECTIVE CONSUMER.................................................................................................................................... 457 DURABLE SUBSCRIBER.................................................................................................................................... 464 IDEMPOTENT RECEIVER................................................................................................................................... 469 SERVICE ACTIVATOR ........................................................................................................................................ 472
11.SYSTEM MANAGEMENT ..................................................................................................................... 476 INTRODUCTION................................................................................................................................................ 476 CONTROL BUS ................................................................................................................................................. 477 DETOUR........................................................................................................................................................... 481 WIRE TAP ........................................................................................................................................................ 482 MESSAGE HISTORY.......................................................................................................................................... 484 MESSAGE STORE ............................................................................................................................................. 487 SMART PROXY ................................................................................................................................................. 489 TEST MESSAGE................................................................................................................................................ 498 CHANNEL PURGER........................................................................................................................................... 500 12.INTERLUDE:SYSTEM MANAGEMENT EXAMPLE..................................................................... 504 LOAN BROKER SYSTEM MANAGEMENT........................................................................................................... 504 13.INTEGRATION PATTERNS IN PRACTICE ....................................................................................... 528 CASE STUDY: BOND TRADING SYSTEM ........................................................................................................... 528 ARCHITECTURE WITH PATTERNS...................................................................................................................... 529 14.CONCLUDING REMARKS.................................................................................................................... 548 EMERGING STANDARDS AND FUTURES IN ENTERPRISE INTEGRATION.............................................................. 548 BIBLIOGRAPHY ............................................................................................................................................. 569
Foreword by John Crupi What do you do when a new technology arrives? You learn the technology. This is exactly what I did. I studied J2EE (being from Sun Microsystems, it seemed to be the logical choice). Specifically, I focused on the EJB technology by reading the specifications (since there were no books yet). Learning the technology, however, is just the first step—the real goal is to learn how to effectively apply the technology. The nice thing about platform technologies is that they constrain you to performing certain tasks. But, as far as the technology is concerned, you can do whatever you want and quite often get into trouble if you don’t do things appropriately. One thing I’ve seen in the past 15 years is that there seem to be two areas that software developers obsess over: programming and designing—or more specifically, programming and designing effectively. There are great books out there that tell you the most efficient way to program certain things in Java and C#, but far fewer tell you how to design effectively. That’s where this book comes in. When Deepak Alur, Dan Malks, and I wrote Core J2EE Patterns, we wanted to help J2EE developers “design” better code. The best decision we made was to use patterns as the artifact of choice. As James Baty, a Sun Distinguished Engineer, puts it, “Patterns seem to be the sweet spot of design.” I couldn’t agree more, and luckily for us, Gregor and Bobby feel the same way. This book focuses on a hot and growing topic: integration using messaging. Not only is messaging key to integration, but it will most likely be the predominant focus in Web services for years to come. There is so much noise today in the Web services world, it’s a delicate and complex endeavor just to identify the specifications and technologies to focus on. The goal remains the same, however— software helps you solve a problem. Just as in the early days of J2EE and .NET, there is not a lot of design help out there yet for Web services. Many people say Web services is just a new and open way to solve our existing integration problems— and I agree. But, that doesn’t mean we know how to design Web services. And that brings us to the gem of this book. I believe this book has many of the patterns we need to design Web services and other integration systems. Because the Web service specifications are still battling it out, it wouldn’t have made sense for Bobby and Gregor to provide examples of many of the Web service specifications. But, that’s okay. The real payoff will result when the specifications become standards and we use the patterns in this book to design for those solutions that are realized by these standards. Then maybe we can realize our next integration goal of designing for service-oriented architectures. Read this book and keep it by your side. It will enhance your software career to no end. John Crupi Bethesda, MD August 2003
Foreword by Martin Fowler While I was working on my book Patterns of Enterprise Application Architecture, I was lucky to get some in-depth review from Kyle Brown and Rachel Reinitz at some informal workshops at Kyle’s office in Raleigh-Durham. During these sessions, we realized that a big gap in my work was asynchronous messaging systems. There are many gaps in my book, and I never intended it to be a complete collection of patterns for enterprise development. But the gap on asynchronous messaging is particularly important because we believe that asynchronous messaging will play an increasingly important role in enterprise software development, particularly in integration. Integration is important because applications cannot live isolated from each other. We need techniques that allow us to take applications that were never designed to interoperate and break down the stovepipes so we can gain a greater benefit than the individual applications can offer us. Various technologies have been around that promise to solve the integration puzzle. We all concluded that messaging is the technology that carries the greatest promise. The challenge we faced was to convey how to do messaging effectively. The biggest challenge in this is that messages are by their nature asynchronous, and there are significant differences in the design approaches that you use in an asynchronous world. I didn’t have space, energy, or frankly the knowledge to cover this topic properly in Patterns of Enterprise Application Architecture. But we came up with a better solution to this gap: find someone else who could. We hunted down Gregor and Bobby, and they took up the challenge. The result is the book you’re about to read. I’m delighted with the job that they have done. If you’ve already worked with messaging systems, this book will systematize much of the knowledge that you and others have already learned the hard way. If you are about to work with messaging systems, this book will provide a foundation that will be invaluable no matter which messaging technology you have to work with. Martin Fowler Melrose, MA August 2003
Preface This is a book about enterprise integration using messaging. It does not document any particular technology or product. Rather, it is designed for developers and integrators using a variety of messaging products and technologies, such as: • Message-oriented middleware (MOM) and integration suites offered by vendors such as the IBM (WebSphere MQ Family), Microsoft (BizTalk), TIBCO, WebMethods, SeeBeyond, Vitria, and others Java Message Service (JMS) implementations incorporated into commercial and open-source J2EE application servers as well as standalone products • • Microsoft’s Message Queuing (MSMQ), accessible through several API’s, including the System.Messaging libraries in Microsoft .NET • Emerging Web services standards that support asynchronous Web services (for example, WS-ReliableMessaging) and the associated API’s such as Sun’s Java API for XML Messaging (JAXM) or Microsoft’s Web Services Extensions (WSE). Enterprise integration goes beyond creating a single application with a distributed n-tier architecture, which enables a single application to be distributed across several computers. Whereas one tier in a distributed application cannot run by itself, integrated applications are independent programs that can each run by itself, yet that function by coordinating with each other in a loosely coupled way. Messaging enables data or commands to be sent across the network using a “send and forget” approach where the caller sends the information and then goes on to other work while the information is transmitted by the messaging system. Optionally, the caller can later be notified of the result through a callback. Asynchronous calls and callbacks can make a design more complex than a synchronous approach, but an asynchronous call can be retried until it succeeds, which makes the communication much more reliable. Asynchronous messaging also enables several other advantages such as throttling of requests and load balancing. Who Should Read This Book This book is designed to help application developers and system integrators connect applications using message-oriented middleware products: • Application architects and developers who design and build complex enterprise applications that need to integrate with other applications. We assume that you’re developing your applications using a modern enterprise application platform such as the Java 2 Platform, Enterprise Edition (J2EE) or the Microsoft .NET framework. This book will help you connect the application to a messaging layer and exchange information with other applications. This book focuses on the integration of applications, not on
分享到:
收藏