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.

AQRawPayload raw_payload;<br />

AQEnqueueOption enq_option;<br />

String test_data = "new message";<br />

AQDequeueOption deq_option;<br />

byte[] b_array;<br />

Connection db_conn;<br />

db_conn = ((AQ<strong>Oracle</strong>Session)aq_sess).getDBConnection();<br />

Enqueuing and Dequeuing Of Messages<br />

/* Get a handle to queue table - aq_table4 in aqjava schema: */<br />

q_table = aq_sess.getQueueTable ("aqjava", "aq_table4");<br />

System.out.println("Successful getQueueTable");<br />

/* Get a handle to a queue - aq_queue4 in aquser schema: */<br />

queue = aq_sess.getQueue ("aqjava", "aq_queue4");<br />

System.out.println("Successful getQueue");<br />

/* Creating a message to contain raw payload: */<br />

message = queue.createMessage();<br />

/* Get handle to the AQRawPayload object and populate it with raw data: */<br />

b_array = test_data.getBytes();<br />

raw_payload = message.getRawPayload();<br />

raw_payload.setStream(b_array, b_array.length);<br />

/* Creating a AQEnqueueOption object with default options: */<br />

enq_option = new AQEnqueueOption();<br />

/* Enqueue the message: */<br />

queue.enqueue(enq_option, message);<br />

System.out.println("Successful enqueue");<br />

db_conn.commit();<br />

/* Creating a AQDequeueOption object with default options: */<br />

deq_option = new AQDequeueOption();<br />

/* Set dequeue mode to BROWSE: */<br />

deq_option.setDequeueMode(AQDequeueOption.DEQUEUE_BROWSE);<br />

/* Set wait time to 10 seconds: */<br />

deq_option.setWaitTime(10);<br />

<strong>Oracle</strong> <strong>Advanced</strong> <strong>Queuing</strong> by Example A-29

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

Saved successfully!

Ooh no, something went wrong!