10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Creating Robust JMS Applications<br />

944<br />

outMessage = session.createMapMessage();<br />

// Add content to message<br />

producer.send(outMessage);<br />

// Display message contentssession.commit();<br />

4. <strong>The</strong> vendor receives the replies from the suppliers from its confirmation queue and updates<br />

the state of the order. Messages are processed by an asynchronous message listener; this step<br />

shows the use of JMS transactions with a message listener.<br />

MapMessage component = (MapMessage) message;<br />

...<br />

orderNumber = component.getInt("VendorOrderNumber");<br />

Order order = Order.getOrder(orderNumber).processSubOrder(component);<br />

session.commit();<br />

5. When all outstanding replies are processed for a given order, the vendor message listener<br />

sends a message notifying the retailer whether it can fulfill the order.<br />

Queue replyQueue = (Queue) order.order.getJMSReplyTo();<br />

MessageProducer producer = session.createProducer(replyQueue);<br />

MapMessage retailerConfirmMessage = session.createMapMessage();<br />

// Format the message<br />

producer.send(retailerConfirmMessage);<br />

session.commit();<br />

6. <strong>The</strong> retailer receives the message from the vendor:<br />

inMessage = (MapMessage) orderConfirmReceiver.receive();<br />

Figure 31–10 illustrates these steps.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!