Enterprise Integration Patterns

Transcription

Enterprise Integration PatternsAsynchronous Messaging Architecturesin PracticeTranslatorTest MessageSplitterAggregatorEnricherGregor Hohpe

Integration Challenges Users want to execute businessfunctions that span multiple applications Requires disparate applications to beconnected to a common integrationsolution However:––––Networks are slowNetworks are unreliableNo two applications are alikeChange is InevitableEnterprise Integration PatternsCopyright 2003 Gregor HohpeIsolated SystemsUnified Access2

Message-Oriented MiddlewareMessage-oriented architectures provide loosecoupling and reliabilitySystemAChannelSystemBMessage¾ Remove location Channels are separate fromdependenciesapplications Channels are asynchronous & ¾ Remove temporaldependenciesreliable¾ Remove data format Data is exchanged in selfdependenciescontained messagesEnterprise Integration PatternsCopyright 2003 Gregor Hohpe3

Thinking AsynchronouslyOrder MgmtWeb SiteShippingInventoryNew OrderOrder MgmtWeb SiteShippingInventoryNew OrderConfirmNew OrderConfirmIdleNew OrderConfirmConfirmSynchronousEnterprise Integration PatternsAsynchronousCopyright 2003 Gregor Hohpe4

Many Products & Implementations Message-oriented middleware (MOM)– IBM WebSphere MQ– Microsoft MSMQ– Java Message Service (JMS) Implementations EAI Suites– TIBCO, WebMethods, SeeBeyond, Vitria, . Asynchronous Web servicesHOTHOT– WS-ReliableMessaging, ebMS– Sun’s Java API for XML Messaging (JAXM)– Microsoft’s Web Services Extensions (WSE)The Underlying Design Principles Are the Same!Enterprise Integration PatternsCopyright 2003 Gregor Hohpe5

Catalog of 65 Patterns1. Request-ReplyExampleMessageConstructionCommand MessageRPC MessageQuery MessageDocument MessageEvent MessageReply MessageReturn AddressCorrelation IdentifierMessage SequenceMessage ExpirationCanonical Data ModelFormat Indicator2. Order ManagementExampleMessageRoutingContent-Based RouterMessage FilterRecipient ListSplitterAggregatorResequencerDistribution w. Aggr. Resp.AuctionRouting TableProcessManagerMessageTransformationData EnricherContent FilterCheck gEndpointsMessaging AdapterPolling ConsumerEvent-Driven ConsumerTransactional ClientCompeting ConsumersMessage DispatcherMessage SelectorIdempotent ReceiverMessaging MapperEnterprise Integration ngChannelsPoint-to-Point ChannelPublish-Subcr. ChannelDurable SubscriberDatatype ChannelInvalid Message ChannelDead Letter ChannelGuaranteed MessagingChannel AdapterMonitoringCopyright 2003 Gregor HohpeSystemsManagement3. BonusControl BusMessage HeaderEnvelope WrapperMessage HistoryMessage StoreChannel PurgerTest Message6

Pattern: Request-ReplyConsumerRequestProviderRequest ChannelReply Channel ReplyService Provider and Consumer (similar to RPC)Channels are unidirectionalTwo asynchronous Point-To-Point ChannelsSeparate request and reply messagesEnterprise Integration PatternsCopyright 2003 Gregor Hohpe7

Multiple ConsumersRequestsRequestsProviderRequest ChannelConsumerConsumer11ConsumerConsumer22Reply Channel 1Reply Channel 2?Replies Each consumer has its own reply queue How does the provider know where to send the reply?– Could send to all consumers Æ very inefficient– Hard code Æ violates principle of context-free serviceEnterprise Integration PatternsCopyright 2003 Gregor Hohpe8

Pattern: Return AddressReplyChannel 1ReplyChannel 2ProviderRequest ChannelConsumerConsumer11ConsumerConsumer22Reply Channel 1Reply Channel 2Replies Consumer specifies Return Address (reply channel) in therequest message Service provider sends reply message to specifiedchannelEnterprise Integration PatternsCopyright 2003 Gregor Hohpe9

Multiple Service ProvidersProviderProvider 11Request ChannelConsumerConsumerProviderProvider 22Reply Channel Request message can be consumed by more than oneservice provider Point-to-Point Channel supports Competing Consumers,only one service receives each request message Channel queues up pending requestsEnterprise Integration PatternsCopyright 2003 Gregor Hohpe10

Multiple Service ProvidersConsumerService 1(slow)Request 1Request 2Reply 2Reply 1Enterprise Integration PatternsService 2(fast) Reply messages get outof sequence How to match request andreply messages?– Only send one request at atimeÆ very inefficient– Rely on natural orderÆ bad assumptionCopyright 2003 Gregor Hohpe11

Pattern: Correlation IdentifierConsumer1212MessageIdentifierRequest ChannelCorrelateRequest &Reply21211ProviderProvider 1122ProviderProvider 221Response ChannelCorrelationIdentifier Equip each message with a unique identifier– Message ID (simple, but has limitations)– GUID (Globally Unique ID)– Business key (e.g. Order ID) Provider copies the ID to the reply message Consumer can match request and responseEnterprise Integration PatternsCopyright 2003 Gregor Hohpe12

Pattern: upDe-DupFilter‘Clean’Order Connect individual processing steps (filters) with messagechannels (pipes)– Pipes decouple sender and receiver– Participants are unaware of intermediaries– Compose patterns into larger solutionsEnterprise Integration PatternsCopyright 2003 Gregor Hohpe13

Multiple Specialized idget Inv.Inv.GadgetGadget Inv.Inv. Each provider can only handle specific type of message Route request to the “appropriate” provider based on thecontent of the request message– Do not want to burden sender with decision (decoupling)– Letting each consumer “pick out” desired messages requiresdistributed coordinationEnterprise Integration PatternsCopyright 2003 Gregor Hohpe14

Pattern: Content-Based RouterOrderMessagesWidgetWidget etGadget Inv.Inv. Insert a Content-Based Router Message routers forward incoming messages to differentoutput channels Message content not changed Mostly stateless, but can be stateful (e.g. de-duper)Enterprise Integration PatternsCopyright 2003 Gregor Hohpe15

Composite et Inv.Inv.GadgetGadget Inv.Inv. How can we process a message if it contains multipleelements, each of which may have to be processed in adifferent way?– Treat each element independently– Need to avoid missing or duplicate elements– Make efficient use of network resourcesEnterprise Integration PatternsCopyright 2003 Gregor Hohpe16

Pattern: SplitterOrderMessageWidgetWidget Inv.Inv.OrderOrderEntryEntry?SplitterOrder OrderItem 1 Item 2GadgetGadget Inv.Inv. Use a Splitter to break out the composite message into aseries of individual messages, each containing datarelated to one item.Enterprise Integration PatternsCopyright 2003 Gregor Hohpe17

Composite: Splitter & RouterOrderItem 1OrderMessageWidgetWidget Inv.Inv.OrderOrderEntryEntrySplitterOrder OrderItem 1 Item 2GadgetGadget Inv.Inv.RouterOrderItem 2 Use a Splitter to break out the composite message into aseries of individual messages, each containing datarelated to one item. Then use a Content-Based Router to route the individualmessages to the proper destinationEnterprise Integration PatternsCopyright 2003 Gregor Hohpe18

Producing a Single ResponseOrderItem 1Response 1ConfirmedOrderWidgetWidget Inv.Inv.?GadgetGadget Inv.Inv.OrderItem 2BillingBillingResponse 2 How to combine the results of individual, but relatedmessages so that they can be processed as a whole?––––Messages out of orderMessage delayedWhich messages are related?Avoid separate channel for each systemEnterprise Integration PatternsCopyright 2003 Gregor Hohpe19

Pattern: AggregatorOrderItem 1Response 1ConfirmedOrderWidgetWidget Inv.Inv.BillingBillingGadgetGadget Inv.Inv.OrderItem 2AggregatorResponse 2 Use a stateful filter, an Aggregator, to collect and storeindividual messages until a complete set of relatedmessages has been received.– Aggregator publishes a single message distilled from theindividual messages.– Correlation– Completeness Condition– Aggregation AlgorithmEnterprise Integration PatternsCopyright 2003 Gregor Hohpe20

Pattern: Scatter-Gather Send a message to a dynamic set of recipients,and return a single message that incorporates est“Best”QuoteEnterprise Integration PatternsVendorVendor AAQuoteVendorVendor BBVendorVendor CCAggregatorCopyright 2003 Gregor Hohpe21

Composing Patterns Receive an order, get best offer for each itemfrom vendors, combine into validated ValidatedOrderAggregatorEnterprise Integration PatternsQuote Requestfor each item“Best” Quotefor each itemVendorVendor AAQuoteVendorVendor BBVendorVendor CCAggregatorCopyright 2003 Gregor Hohpe22

System Management Messaging systems are asynchronous anddistributed– Multiple platforms– Difficult to detect errors– Difficult to configure (property file hell) How can we effectively administer a messagingsystem that is distributed across multipleplatforms and a wide geographic area?Enterprise Integration PatternsCopyright 2003 Gregor Hohpe23

Pattern: Control BusApplication Message FlowControl BusManagementConsole ConfigurationHeartbeatTest messagesExceptions / loggingStatistics / Quality-of-Service (QoS)Live consoleEnterprise Integration PatternsCopyright 2003 Gregor Hohpe24

How To Inspect Messages?Point-To-Point entConsole Cannot add another receiver because it would consumethe message Cannot switch to Publish-Subscribe-Channel becausePoint-To-Point Channelmay already have Competing ConsumersEnterprise Integration PatternsCopyright 2003 Gregor Hohpe25

Pattern: Wire TapWire ementConsole Simple Router that duplicates message to two outputchannels Also known as Tee Some side effects: Message ID changes, latencyEnterprise Integration PatternsCopyright 2003 Gregor Hohpe26

Track MessagesWire TapWire TapComponentComponentAnalysis E.g., message run time, message volume Missed messages if channels or component unreliableEnterprise Integration PatternsCopyright 2003 Gregor Hohpe27

What if Return Address is Used?Wire TapConsumerConsumerConsumerConsumerRequest ChannelProviderReply Channels? Provider routes reply message to dynamic channel Cannot dynamically inject Wire TapEnterprise Integration PatternsCopyright 2003 Gregor Hohpe28

Pattern: Smart ProxySmart ProxyConsumerConsumerRequest ChannelProviderFixed Reply ChannelConsumerConsumerReplyChannels A Smart Proxy stores original Return Address andreplaces it with a fixed channel address Intercepts reply messages and forwards them to correctchannel Allows analysis of request and reply messagesEnterprise Integration PatternsCopyright 2003 Gregor Hohpe29

Pattern: Test MessageTest MessageInjectorTest MessageSeparatorProcessorProcessorAppl. Appl.Msg. 1 Msg. 2TestMessage9Test DataGeneratorAppl.Msg. 1TestResultAppl.Msg. 2Test DataVerifierControl BusManagement Console Inject application specific test messages Extract result from regular message flow Compare result against predefined (or computed) resultEnterprise Integration PatternsCopyright 2003 Gregor Hohpe30

In Summary Visual and verbal language to describeintegration solutions Combine patterns to describe larger solutions No fancy tools – whiteboard or PowerPoint No vendor jargon Not a precise specification language– (e.g., see OMG UML Profile for EAI) Not a new “methodology” Each pattern describes trade-offs andconsiderations not included in this overviewEnterprise Integration PatternsCopyright 2003 Gregor Hohpe31

Resources Book (late October):– Enterprise Integration Patterns– Addison-Wesley, 0-321-20068-3 Contact– Gregor Hohpe– ghohpe@thoughtworks.com Web Site––––http://www.eaipatterns.comPattern catalogBibliography, related papersinfo@eaipatterns.com www.thoughtworks.comEnterprise Integration PatternsCopyright 2003 Gregor Hohpe32

Enterprise Integration Patterns Asynchronous Messaging Architectures in Practice Test Mes