2011-12-22 23 views
1

standalone javaを使用してOracle 11gキューを使用してデキューしようとしています。ここでは、コードは次のようになります。Java for Oracle 11gキューをデキューする

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(); 
    } 
    } 

しかし、私は以下の行でエラーを取得しています。エラーが

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) 

は、いずれかがこのエラーを修正するために私を助けることができると言う

message = queue.dequeue(deq_option); 

?メッセージを一括でデキューする必要があります。

ありがとうございます!

答えて

1

正確にエンキューするのは何ですか?あなたのペイロードは何ですか?
Oracle Streams AQを作成するときは、キューにエンキューされるペイロード・タイプを指定する必要があります。
オブジェクト・ペイロード・タイプの場合は、キュー解除前にクラス情報をAQSessionに追加する必要があります。例えばOraclesのネイティブXMLTypeオブジェクトをデキューするので、セッションの作成直後に次のコードを追加する必要があります。

Map map = session.getTypeMap(); 
map.put("SYS.XMLTYPE", Class.forName("oracle.xdb.XMLTypeFactory")); 

ペイロードタイプに基づいて同様の操作を行う必要があります。

+0

こんにちは。お手伝いできますか?ペイロードタイプはsys.aq $ _jms_text_message – Mike

+0

キュー作成スクリプトとエンキューコードを共有できますか? –