سؤال

With Oracle's Advanced Queuing is there a way to dequeue messages in a LIFO (last in first out) order? There is an indication through a lack of information that this is not an option, but perhaps there is a way to do this such as queuing in a different order.

هل كانت مفيدة؟

المحلول

Assuming that you are using PL/SQL to dequeue the message (there may be additional JMS limitations-- I don't know enough about the interplay between JMS and AQ), you should be able to use a priority queue to implement LIFO (though it would be a bit hokey). When you enqueue a message, you can specify a priority

The priority attribute specifies the priority of the message. It can be any number, including negative numbers. A smaller number indicates higher priority.

If you create a sequence that counts back from some really large number, you could assign an ever increasing priority. Then your prioritized dequeue would get messages in a LIFO order.

نصائح أخرى

To get LIFO behavior in Oracle, you could implement a stack using a PL/SQL object:

A stack holds an ordered collection of data items. Stacks have a top and a bottom. Items can be added or removed only at the top. So, the last item added to a stack is the first item removed. (Think of the stack of clean serving trays in a cafeteria.) The operations push and pop update the stack while preserving last in, first out (LIFO) behavior.

Stacks have many applications. For example, they are used in systems programming to prioritize interrupts and to manage recursion. The simplest implementation of a stack uses an integer array, with one end of the array representing the top of the stack.

Then you would need to wrap your enqueue/dequeue functions so instead of passing through to AQ, they would instead go to your stack rather than the AQ tables.

The whitepaper for Oracle 12c explicitly calls out using a LIFO queue as an option, but I can't find a good reference in actual the doco as to how you'd do that:

"Alternately, messages can also be sorted according to enqueue time, commit time, or priority to get a FIFO or even LIFO order for consuming the messages" http://www.oracle.com/technetwork/database/oracleadvancedqueuingwp-2524215.pdf

(one option I can think of is to have a priority-sorted queue with the priority being monotonically increasing at the producer: if an int64 priority is allowed that would give quite a bit of headroom...)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى dba.stackexchange
scroll top