09.12.2012 Views

Advanced Queuing - Oracle

Advanced Queuing - Oracle

Advanced Queuing - Oracle

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

JMS Message Consumer Features<br />

This mode allows the JMS client to avoid the overhead of retrieving the payload<br />

from the database, which can be substantial for a large message.<br />

Example Scenario and Code<br />

In the following scenario from the BooksOnLine example, international orders<br />

destined to Mexico and Canada are to be processed separately due to trade policies<br />

and carrier discounts. Hence, a message is viewed in the locked mode (so no other<br />

concurrent user removes the message) using the QueueBrowser and the customer<br />

country (message payload) is checked. If the customer country is Mexico or Canada<br />

the message be deleted from the queue using the remove with no data (since the<br />

payload is already known) mode. Alternatively, the lock on the message is released<br />

by the commit call. Note that the receive call uses the message identifier obtained<br />

from the locked mode browse.<br />

public void process_international_orders(QueueSession jms_session)<br />

{<br />

QueueBrowser browser;<br />

Queue queue;<br />

ObjectMessage obj_message;<br />

BolOrder new_order;<br />

Enumeration messages;<br />

String customer_name;<br />

String customer_country;<br />

QueueReceiver qrec;<br />

String msg_sel;<br />

try<br />

{<br />

/* get a handle to the new_orders queue */<br />

queue = ((AQjmsSession) jms_session).getQueue("OE", "OE_neworders_que");<br />

/* create a Browser to look at RUSH orders */<br />

browser = ((AQjmsSession)jms_session).createBrowser(queue, null, true);<br />

for (messages = browser.getEnumeration() ; messages.hasMoreElements() ;)<br />

{<br />

obj_message = (ObjectMessage)messages.nextElement();<br />

new_order = (BolOrder)obj_message.getObject();<br />

customer_name = new_order.getCustomer().getName();<br />

customer_country = new_order.getCustomer().getCountry();<br />

Creating Applications Using JMS 12-73

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

Saved successfully!

Ooh no, something went wrong!