Oracle AQ Dequeue Order By ENQ_TID

67 Views Asked by At

Uisng Oracle AQ on v 19c.

Message are enqueued via triggers. Some triggers are invoked that will write a master/detail set of message to the queue e.g:

Parent1
Parent1,Child1
Parent1,Child2
Parent2
Parent2,Child3

This work fine, but we are now seeing instances where the messages from different parents are interspersed eg:

Parent1
Parent1,Child1
Parent2
Parent1,Child2
Parent2,Child3

This messes up the dequeue. There is however a enq_tid column on the queue table, which groups the messages together correctly. So if I could dequeue with the order specified as ENQ_TID, ENQ_TIME that should solve my problem.

I have been looking at which I need to specify in the DBMS_AQ.DEQUEUE_OPTIONS_T but I cannot find any examples in the documentation where the ORDER BY can be controlled.

DECLARE
  parray   MyArrayType;
  deqopts  DBMS_AQ.DEQUEUE_OPTIONS_T;
  msgprops DBMS_AQ.MESSAGE_PROPERTIES_ARRAY_T;
  msgids   DBMS_AQ.MSGID_ARRAY_T;
BEGIN
  deqopts.wait          := DBMS_AQ.NO_WAIT;
  deqopts.consumer_name := 'cname';
  deqopts.navigation    := DBMS_AQ.FIRST_MESSAGE;
  DBMS_AQ.DEQUEUE_ARRAY ( queue_name => 'theQ',
                          dequeue_options => depopts,
                          array_size  => 200,
                          message_properties_array => msgprops,
                          payload_array => parray,
                          msgid_array => msgids );
  FOR idx IN parray.FIRST .. parry.LAST LOOP
   -- process
  END LOOP;
END;
/
0

There are 0 best solutions below