June 2004
Intermediate to advanced
792 pages
23h 17m
English
Message linking is a new feature to EJB
2.1 that allows the messages being sent by any enterprise bean to be
routed to a specific message-driven bean in the same deployment. By
using message linking, you can orchestrate a flow of messages between
components in the same application. For example, in the beginning of
this chapter, the TravelAgent EJB from Chapter 11 was re-implemented so that it sent a JMS
message with the ticket information to a Topic destination.
Here’s a different implementation of the TravelAgent
EJB’s bookPassage( ) method, this
time using an ObjectMessage type:
public TicketDO bookPassage(CreditCardDO card, double price)
throws IncompleteConversationalState {
if (customer == null || cruise == null || cabin == null) {
throw new IncompleteConversationalState( );
}
try {
ReservationHomeLocal resHome = (ReservationHomeLocal)
jndiContext.lookup("java:comp/env/ejb/ReservationHomeLocal");
ReservationLocal reservation =
resHome.create(customer, cruise, cabin, price, new Date( ));
Object ref = jndiContext.lookup
("java:comp/env/ejb/ProcessPaymentHomeRemote");
ProcessPaymentHomeRemote ppHome = (ProcessPaymentHomeRemote)
PortableRemoteObject.narrow(ref, ProcessPaymentHomeRemote.class);
ProcessPaymentRemote process = ppHome.create( );
process.byCredit(customer, card, price);
TicketDO ticket = new TicketDO(customer,cruise,cabin,price);
TopicConnectionFactory factory = (TopicConnectionFactory)
jndiContext.lookup("java:comp/env/jms/TopicFactory"); ...Read now
Unlock full access