Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to dequeue Oracle queue(enqueue in Ora) in java using JMS text message

909967Jan 10 2012
I'm trying below java code but its giving me error:

public class testq {
public static void main(String[] args) throws Exception {
testq q = new testq();

AQSession aq_sess = createSession();
q.runTest(aq_sess);
}

public static AQSession createSession() {
Connection db_conn;
AQSession aq_sess = null;

try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

/* Load the Oracle8i AQ driver: */
Class.forName("oracle.AQ.AQOracleDriver");

db_conn = DriverManager.getConnection("jdbc:oracle:thin:@10.10.10.10:1521:demo", "demo_app", "demo");

System.out.println("JDBC Connection opened ");
db_conn.setAutoCommit(false);


/* Creating an AQ Session: */
aq_sess = AQDriverManager.createAQSession(db_conn);
System.out.println("Successfully created AQSession ");
}
catch (Exception ex) {
System.out.println("Exception: " + ex);
ex.printStackTrace();
}
return aq_sess;
}

public void runTest(AQSession aq_sess) {
//AQQueueTable q_table;
AQQueue queue;
AQMessage message;
AQRawPayload raw_payload;
AQDequeueOption deq_option;
byte[] b_array;
Connection db_conn;

try {
db_conn = ((AQOracleSession)aq_sess).getDBConnection();

/* Get a handle to a queue - aq_queue4 in aquser schema: */
queue = aq_sess.getQueue ("myadmin", "STREAM_QUEUE_DEMO");
System.out.println("Successful getQueue");

/* Creating a AQDequeueOption object with default options: */
deq_option = new AQDequeueOption();

deq_option.setDequeueMode(AQDequeueOption.DEQUEUE_REMOVE);

/* Set wait time to 10 seconds: */
deq_option.setWaitTime(10);

/* Dequeue a message: */
message = queue.dequeue(deq_option);
System.out.println("Successful dequeue");

/* Retrieve raw data from the message: */
raw_payload = message.getRawPayload();
b_array = raw_payload.getBytes();
db_conn.commit();

String value = new String(b_array);
System.out.println("queue="+value);
} catch(Exception e) {
e.printStackTrace();
}
}

The error says "oracle.AQ.AQException: JMS-174: Class must be specified for queues with object payloads
Use dequeue(deq_option, payload_fact) or dequeue(deq_option, sql_data_cl)"

Can any one tell me how to fix this error & how to get bulk dequeue messages?

And i am using sys.AQ$_JMS_TEXT_MESSAGE payload type during enqueue.

Can any one tell me how to fix this Java program to dequeue it?

Thanks in advance...Please its urgent

Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 7 2012
Added on Jan 10 2012
0 comments
454 views