200 likes | 515 Views
Message Oriented Middleware (MOM) Cache Pattern. Harini Srinivasan, Eoin Lane, Lei He,Tim Banks IBM Software Group {harini, eoinlane}@us.ibm.com heleihl@cn.ibm.com tim_banks@uk.ibm.com. Fang Yan Rao, Ru Fang, Zhong Tian IBM China Research Lab {raofy,fangru,tianz}@cn.ibm.com. Motivation.
E N D
Message Oriented Middleware (MOM) Cache Pattern Harini Srinivasan, Eoin Lane, Lei He,Tim Banks IBM Software Group {harini, eoinlane}@us.ibm.com heleihl@cn.ibm.com tim_banks@uk.ibm.com Fang Yan Rao, Ru Fang, Zhong Tian IBM China Research Lab {raofy,fangru,tianz}@cn.ibm.com
Motivation • In a Service Oriented Architecture (SOA) environment, when the communication channel between service provider and consumer is Message Oriented Middleware (MOM), how to accelerate service response time is the problem the MOM cache pattern is targeting to solve.
Background of Cache • Cache is a collection of Cache Item • Cache Item is (key, data) pairs • Data is identified by its key in Cache • A cache has a basic method “Object hitCache(Object key)” to retrieve data from cache according to its key, and refresh cache if it is missed according to certain cache refreshing policy • Use existing cache solutions • Websphere DynaCache • JBossCache • SpiritCache • JCache
Pattern at Architectural Level - Alternatives of Cache Design Service Provider Service Provider Service Provider Cache Cache Cache Service Consumer Service Consumer Service Consumer Server Side Cache Client Side Cache MOM Cache Our Focus
Message Exchange Between Service Provider and Service Consumer in MOM • In MOM, the request message and response message are delivered independently. And processors of request and response message also work independently and asynchronously. Service Consumer Mediation of Message Routed to Service Provider Mediation of Message Routed to Service Consumer Service Provider Request Message … Request Message Response Message … Response Message
Cache Mediation • Shorten service response time by caching service response message correlated with request message in MOM. When identical request message is issued, message system retrieve correlated response message from cache and return the message directly to service consumer, instead of forwarding the request message to service provider. By doing so minimize costly remote service invocation and improve service response time. Mediation w/ Cache Request Message Cached Response Message Figure revised from: Enterprise Service Bus – Making SOA Real, Beth Hutchison, Peter Lambros, Rob Phippen, Marc-Thomas Schmidt
Challenge 1: Identify Request and Response • Cache needs to identify the request and corresponding response to accelerate service responsiveness. • Neither request mediation nor response mediation can identify request message and its corresponding response message in the same invocation of the hitCache method like illustrated in the sample code . • Assuming MOM cache provides message correlating mechanism, how to design add cache to request mediation and response mediation, and they can collaboratively identify request and corresponding response messages?
Pattern Structure – Two Cache Mediations Coupled by One Cache Asynchronous Messaging System Cache Mediation of Messages Routed to Service Provider 2 1 a b Service Consumer Service Provider Cache 3 4 Cache Mediation of Messages Routed to Service Consumer • Participants: • Cache mediation of request message • Cache mediation of response message • Cache shared between both mediations Ordinary Message Flow Accelerated Message Flow
Cache Contents • Cache entry = (cache key, cache item) • Major cache entry • Cache key is composed from: • User defined cache key • Example • Hash code of (request message destination, service operation, service operation parameter) • Message identification method provided by messaging middleware • Cache item is composed from: • Response message • Supportive cache entry • (message ID, cache key)
Applicability • Communication channel • Communication channel between service provider and consumer is messaging. • Cache location • Message mediation in messaging middleware. Cache on other places like EBJ container is not applicable. • Invocation style • Invoke and response, where one response message is generated according to one request. Other invocation style like pub-sub is not applicable to this pattern. • Service provider side tolerance • The service to be accelerated can tolerate identical request is not delivered to it and response is cached by messaging middleware. This requires • Service is not transactional • Data change frequency is not high, or data expiration time is not short • Data auditing policy allows request data not arrive at service provider • Data privacy policy allows data cached in communication channel
Consequences • Behavior • Behavior of messaging middleware is changed. It actively changes the routing path of request message and sends cached response message back to service consumer. • Service provider will not receive every request messages. • Data • With cache in messaging middleware, response message may not be up to date. The data staleness cache brought needs to be understood by cache users, and can be alleviated by cache data refreshing policy. • Performance • It increases the responsiveness of service by caching request and correlated response message. However, cache has its related cost. Message mediations need extra cost to access payload of messages and store cached messages.
Dependency • Message Correlation • Messaging middleware needs to provide message correlation mechanism to correlate request and corresponding response messages • Correlation can be either automatically done by messaging middleware, or by service provider with correlation APIs provided by underlying messaging system. • Message identification • Message middleware can provide faster message identification options so that pattern users can choose appropriate message identification for cache item identification key generation and comparison.
Implementation Based On WebSphere Application Server (WAS) v 6 • WAS v 6 has platform messaging to provide asynchronous messaging capability. On top of it WAS v 6 has SIBus to support message-based and service-oriented architectures. • Implementation of cache mediation is cache mediation handler EJBs deployed on WAS, together with a set of configurations of SIBus. • Built on top of DistributedMap cache provided in WAS.
Pattern Codified in Rational Software Architect • RSA has pattern authoring and application capability to codify the pattern. • Apply the pattern to UML model in RSA, and the pattern can automatically generate code and deployment script for cache mediations
Demo of Pattern Application Apply Pattern UML to UML Transformation to Generate Deployment Model UML to Java Transformation to Generate Runtime Artifact
RequestCacheMediationHandler didn’t find the cache key and insert a new cache entrywith empty response message in cache item. Runtime Screenshot of Weather Forecast Demo ResponseCacheMediationHandler find the cache key and update the cache item with a new response message.
Runtime Screenshot of Weather Forecast Demo (cont.) Second invoking the web service with the same request parameter (Day of Number = 3) RequestCacheMediationHandler get response message from cache and return to service consumer. ResponseCacheMediationHandler needn’t update cache item
Challenge 2: Uniform Underlying Cache API • For Websphere DynaCache • class com.ibm.websphere.cache.DistributedMap implements java.util.Map • Has “get” and “add” method derived from java.util.Map • For other Caches, provide different APIs • How to hide APIs differences so that when different cache implementations provide different APIs, the cache user needn’t change its code?