简体   繁体   中英

Oracle AQ Topic Queue dequeue with ODP.NET

I'm trying for the first time to dequeue from a queue on my company production environment by ODP.NET and C#.

I used the official ODP.NET example to develop my client got from the installation examples folder.

The queue is an Oracle AQ Topic (multi consumer) addressed by many other company services written with J2EE.

I wrote the UDT mapping classes following the ODP development guidelines ( http://docs.oracle.com/cd/E11882_01/win.112/e23174/featUDTs.htm#ODPNT0024 ).

The issue is: my client connects to the queue, by it never gets any message (others connected java clients get them).

Here is my code (without UDT classes, for keep short my post):

        string constr = "user id=<USER_ID>;password=<PASSWORD>;data source=<DATASOURCE>";
        OracleConnection conListen = new OracleConnection(constr);

        OracleAQQueue queueListen = new OracleAQQueue("<TOPIC_QUEUE_ID>", conListen);            

        try
        {
            conListen.Open();

            queueListen.MessageType = OracleAQMessageType.Udt;
            queueListen.DequeueOptions.ConsumerName = "Test_Subscriber_ID";
            queueListen.UdtTypeName = "SYS.AQ$_JMS_TEXT_MESSAGE";
            queueListen.DequeueOptions.Visibility = OracleAQVisibilityMode.OnCommit;
            queueListen.DequeueOptions.Wait = 60;

            OracleTransaction txn = conListen.BeginTransaction();

            OracleAQMessage deqMsg = queueListen.Dequeue();                

            txn.Commit();
        }
        catch (Exception e)
        {
           Console.WriteLine("Error: {0}", e.Message);
        }
        finally
        {
            queueListen.Dispose();
            conListen.Close();
            conListen.Dispose();
        }

Another detail: after the connection the "all_queue_subscribers" view doesn't containt my subscriber "Test_Subscriber_ID".

Thank you all!

Problem solved! I missed to create on my own the subscriber by the following script:

declare
  vQueue      varchar2(255) := '<TOPIC_QUEUE_ID>';
  vId         varchar2(255) := 'Test_Subscriber_ID';
  vSubscriber SYS.AQ$_AGENT;
begin 
  vSubscriber := SYS.AQ$_AGENT(vId, null, null);

  dbms_aqadm.add_subscriber(
    queue_name     => vQueue,
    subscriber     => vSubscriber,
    queue_to_queue => false,
    delivery_mode  => DBMS_AQADM.PERSISTENT
  );

  /*dbms_aqadm.enable_db_access(
    agent_name  => vId,
    db_username => '<USER_ID>'
  );*/
end;

With J2EE the subscriber creation is automatic!

Many thanks, Antonio

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM