09.12.2012 Views

Advanced Queuing - Oracle

Advanced Queuing - Oracle

Advanced Queuing - Oracle

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.

JMS Message Consumer Features<br />

}<br />

System.out.println("Exception: " + ex);<br />

}<br />

Message Listener for All Consumers on a Session<br />

The JMS client can receive messages asynchronously for all the consumers of the<br />

session by setting the MessageListener at the session.<br />

When a message arrives for any of the message consumers of the session, the<br />

onMessage method of the message listener is invoked with the message. The<br />

message listener can commit or abort the receipt of the message. The message<br />

listener will not receive messages if the JMS connection has been stopped. No other<br />

mode for receiving messages must be used in the session once the message listener<br />

has been set.<br />

Example Scenario and Code<br />

In the customer service component of the BooksOnLine example, messages from<br />

different databases arrive at the customer service topics, indicating the state of the<br />

order. The customer service application monitors the topics and whenever there is a<br />

message about a customer order, it updates the order status in the order_status_<br />

table. The application uses the session listener to monitor the different topics.<br />

Whenever there is a message in any of the topics, the onMessage method of the<br />

session MessageListener is invoked.<br />

/* define our message listener class */<br />

public class CustomerListener implements MessageListener<br />

{<br />

TopicSession the_sess;<br />

/* constructor */<br />

CustomerListener(TopicSession my_sess)<br />

{<br />

the_sess = my_sess;<br />

}<br />

/* message listener interface */<br />

public void onMessage(Message m)<br />

{<br />

ObjectMessage obj_msg;<br />

BolCustomer customer;<br />

BolOrder new_order = null;<br />

try<br />

12-78 <strong>Oracle</strong>9i Application Developer’s Guide - <strong>Advanced</strong> <strong>Queuing</strong>

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

Saved successfully!

Ooh no, something went wrong!