Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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.

share|improve this answer
    
I added the plsql tag. –  Leigh Riffel Feb 24 '11 at 14:58
1  
Interesting solution. That definitely sounds like it would work even if it is a bit hokey. –  Leigh Riffel Feb 24 '11 at 15:00

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.