Mediation, Service Provider and Consumer

pityingmushroomInternet και Εφαρμογές Web

7 Αυγ 2012 (πριν από 5 χρόνια και 3 μήνες)

373 εμφανίσεις

SoA Research, China Research Lab

© 200
5

IBM Corporation

2005
-
5
-
19

Message Oriented Middleware (MOM) Cache Pattern

Fang Yan Rao, Ru Fang, Zhong Tian

IBM China Research Lab

{raofy,fangru,tianz}@cn.ibm.com


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


SoA Research, China Research Lab

© 200
5

IBM Corporation

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.

SoA Research, China Research Lab

© 200
5

IBM Corporation

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



SoA Research, China Research Lab

© 200
5

IBM Corporation

Pattern at Architectural Level
-

Alternatives of Cache
Design

Service Consumer

Service Provider

Cache

Service Consumer

Service Provider

Cache

Service Consumer

Service Provider

Server Side Cache

Client Side Cache

MOM Cache

Cache

Our
Focus

SoA Research, China Research Lab

© 200
5

IBM Corporation

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

Service Provider

Mediation of

Message Routed to

Service Provider

Request

Message

Mediation of

Message Routed to

Service Consumer

Response

Message





Response

Message

Request

Message

SoA Research, China Research Lab

© 200
5

IBM Corporation

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.


Figure revised from: Enterprise Service Bus


Making SOA Real, Beth Hutchison, Peter Lambros, Rob Phippen, Marc
-
Thomas Schmidt

Request
Message

Cached Response
Message

Mediation w/
Cache

SoA Research, China Research Lab

© 200
5

IBM Corporation

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?

SoA Research, China Research Lab

© 200
5

IBM Corporation


Pattern Structure


Two Cache Mediations Coupled by
One Cache

Service Provider

Service Consumer

Cache Mediation

of Messages Routed to

Service Provider

Cache Mediation

of Messages Routed to

Service Consumer

Cache

Ordinary Message Flow

Accelerated Message Flow

1

2

3

4

b

a

Participants:



Cache mediation of request message


Cache mediation of response message


Cache shared between both mediations

Asynchronous Messaging
System

SoA Research, China Research Lab

© 200
5

IBM Corporation

Collaboration Between Cache Mediations

SoA Research, China Research Lab

© 200
5

IBM Corporation

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)




SoA Research, China Research Lab

© 200
5

IBM Corporation

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



SoA Research, China Research Lab

© 200
5

IBM Corporation

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.

SoA Research, China Research Lab

© 200
5

IBM Corporation

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.

SoA Research, China Research Lab

© 200
5

IBM Corporation

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.

SoA Research, China Research Lab

© 200
5

IBM Corporation

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

SoA Research, China Research Lab

© 200
5

IBM Corporation

Demo of Pattern Application

UML to UML
Transformation to
Generate Deployment
Model

Apply Pattern

UML to Java
Transformation to
Generate Runtime
Artifact

SoA Research, China Research Lab

© 200
5

IBM Corporation

Runtime Screenshot of Weather Forecast Demo

RequestCacheMediationHandler
didn’t
find the cache key
and insert a new
cache entry

with
empty

response
message in cache item
.

ResponseCacheMedia
tionHandler

find the
cache key
and

update
the cache item
with a
new response
message.

SoA Research, China Research Lab

© 200
5

IBM Corporation

Second invoking the web service
with the
same request parameter

(Day of Number = 3)

RequestCacheMediati
onHandler
get
response message
from cache

and return
to service consumer.

ResponseCacheMediat
ionHandler
needn’t
update cache item

Runtime Screenshot of Weather Forecast Demo (cont.)

SoA Research, China Research Lab

© 200
5

IBM Corporation

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?

SoA Research, China Research Lab

© 200
5

IBM Corporation

Candidate Solution


Factory Method