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.

Queue Sender<br />

JMS Point-to-Point Model Features<br />

A client uses a QueueSender to send messages to a queue. A QueueSender is<br />

created by passing a queue to a session’s createSender method. A client also has<br />

the option of creating a QueueSender without supplying a queue. In that case a<br />

queue must be specified on every send operation.<br />

A client can specify a default delivery mode, priority and time-to-live for all<br />

messages sent by the QueueSender. Alternatively, the client can define these<br />

options on a per message basis.<br />

Example Code<br />

In the BooksOnline application, new orders are to be sent to the new_orders_<br />

queue. After creating a JMS connection and session, we create a sender:<br />

public void enqueue_new_orders(QueueSession jms_session, BolOrder new_order)<br />

{<br />

QueueSender sender;<br />

Queue queue;<br />

ObjectMessage obj_message;<br />

}<br />

Queue Receiver<br />

try<br />

{<br />

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

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

sender = jms_session.createSender(queue);<br />

obj_message = jms_session.createObjectMessage();<br />

obj_message.setJMSCorrelationID("RUSH");<br />

obj_message.setObject(new_order);<br />

sender.send(obj_message);<br />

jms_session.commit();<br />

}<br />

catch (JMSException ex)<br />

{<br />

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

}<br />

A client uses a QueueReceiver to receive messages from a queue. A<br />

QueueReceiver is created using the session’s createQueueReceiver method.<br />

A QueueReceiver can be created with a message selector. This allows the client to<br />

restrict messages delivered to the consumer to those that match the selector.<br />

Creating Applications Using JMS 12-39

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

Saved successfully!

Ooh no, something went wrong!