Message Facade Pattern
Consider wanting to make an Airline Reservation. The client would
need to have the system check the airline for availability and
seating. This can involve a number of steps as outlined below.
If the client had to request each and wait for a response this
could be too long for most users to sit around....you may loose
a customer.
Problems:
- Client does not need immediate response....so why make client
wait for responses.
A Solution.....the Message Facade Pattern
- Now have 1 network request to a Message Facade code (ReserveSeatMDB
message-driven EJB)
- Bundle all of the business logic in a seperated Message Facade
code (ReserveSeatMDB message-driven EJB)
- Do not wait on response:
1) Client creates a Java Message Service (JMS) message and passes
the necessary parameter.
2) Client sends this message to a JMS destination created for
the Reserve Seat use case
3) Upon receiving the message at the destination, the client is
free.
4)The server has a "message-driven bean container" that will attempt
to pass the message to the next avaialbe ReserveSeat message-driven
bean. If all of these are busy the JMS server should wait until
the next one becomes availab.e
5) When a RerserveSeat MDB becomes available, the container will
execute the onMessage() method.
QUESTION: How do we get a response from a Message-Driven class
like our ReserveSeat MDB?
- Send email to user/client.
- Have client application poll using some unique ID to check the
staus of their request.
Synopsis: Message Facade
Name: Message Facade
Context
A client wants to invoke the methods of multiple programs
within the context of one use case and does not require
an immediate response from the server.
Problem (forces)
How can a client invoke methods of multiple classes within
one transaction, without the need to block and wait for
responses from each?
Solution
Use message-driven classes (beans) to create a fault-tolerant,
asynchronous facade. Clients should have access to message-driven
classes (beans) only, not the underlying data layer, business
logic (entity and session beans).
Related Patterns
Session Facade.
|
PROBLEM:
No direct response. (some possbilities with
JMS as transport mechanism...see advanced book on EJB).
Message-Drive code does not throw exceptions
back to clients.
|