The QBorrower and QLender Application
To illustrate how point-to-point messaging works, we will use a
simple decoupled request/reply
example where a QBorrower class makes
a simple mortgage loan request to a QLender class using point-to-point messaging.
The QBorrower class sends the loan
request to the QLender class using a
LoanRequest queue, and based on certain business
rules, the QLender class sends a
response back to the QBorrower class
using a LoanResponseQ queue indicating whether the
loan request was approved or denied. Since the QBorrower is interested in finding out right
away whether the loan was approved or not, once the loan request is
sent, the QBorrower class will block
and wait for a response from the QLender class before proceeding. This simple
example models a typical messaging request/reply scenario.
Configuring and Running the Application
Before looking at the code, let’s look at how the application
works. As with the Chat
application, the QBorrower class
and QLender class both include a
main() method so they can be run as
a standalone Java application. To keep the code vendor-agnostic, both
classes need the connection factory name and queue names when starting
the application. The QLender class
is executed from the command line as follows:
java ch04.p2p.QLender ConnectionFactory RequestQueuewhere ConnectionFactory is
the name of the queue connection factory defined in your JMS provider
and RequestQueue is the name of the
queue that the QLender class should be listening ...