EJB 2.1: Message Linking
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"); ...
Get Enterprise JavaBeans, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.