AQ — dequeueing messages
Objectives — by the end of this page you will be able to:
- pull messages off a queue
- tune dequeue behavior: wait, navigation, visibility, consumer, correlation
- inspect message state and metadata
The Dequeue endpoint
The Dequeue is the consuming endpoint — bound to the queue's TypeInfo+name like Enqueue, it pulls Msg objects off the queue.
Pulls are transactional: consuming a message marks it removed inside your transaction — commit to make it stick, rollback puts it back.
OCI_Dequeue *deq = OCI_DequeueCreate(inf, OTEXT("message_queue"));
OCI_Message *msg = OCI_DequeueGet(deq); /* blocks per wait settings */
if (msg)
{
OCI_Object *obj = OCI_MessageGetObject(msg); /* payload as object */
printf("%s\n", OCI_ObjectGetString(obj, OTEXT("TITLE")));
OCI_MessageFree(msg);
}
OCI_ConnectionCommit(con); /* dequeue is transactional too */
Dequeue deq(inf, "message_queue");
Message msg = deq.Get(); /* blocks per wait settings */
Object obj = msg.GetObject();
std::cout << obj.Get<String>("TITLE") << "\n";
con.Commit();
Dequeue options
| C function | C++ method | Meaning |
|---|---|---|
OCI_DequeueSetWaitTime |
SetWaitTime |
block this long for a message (0 = don't wait, -1 = forever) |
OCI_DequeueGetWaitTime |
GetWaitTime() |
read it |
OCI_DequeueSetNavigation |
SetNavigation |
FIRST_MSG/NEXT_MSG/NEXT_TRANSACTION — cursor behavior |
OCI_DequeueGetNavigation |
GetNavigation() |
read it |
OCI_DequeueSetMode |
SetMode |
remove vs browse (peek without consuming) |
OCI_DequeueGetMode |
GetMode() |
read it |
OCI_DequeueSetVisibility |
SetVisibility |
within-transaction vs immediate |
OCI_DequeueGetVisibility |
GetVisibility() |
read it |
OCI_DequeueSetConsumer |
SetConsumer |
named consumer on multi-consumer queues |
OCI_DequeueGetConsumer |
GetConsumer() |
read it |
OCI_DequeueSetCorrelation |
SetCorrelation |
only msgs with this correlation id |
OCI_DequeueSetRelativeMsgID |
SetRelativeMsgID |
relative positioning |
OCI_DequeueSetAgentList |
SetAgentList |
candidate consumers |
OCI_DequeueListen |
Listen |
which agent should dequeue (multi-consumer) |
OCI_DequeueSubscribe |
Connection::DequeueSubscribe |
async callback (next page) |
Which agent — Listen
For multi-consumer queues, listen tells you which agent should dequeue:
OCI_Agent *a = OCI_DequeueListen(deq, 5); /* wait ≤5s for an agent signal */
if (a) printf("message for consumer %s\n", OCI_AgentGetName(a));
Agent a = deq.Listen(5); /* wait ≤5s for an agent signal */
if (a)
{
std::cout << "message for consumer " << a.GetName() << "\n";
}
Message metadata on the way out
Attempt count, enqueue time, state (READY/WAITING/PROCESSED/EXPIRED), id, correlation, sender, original id, exception queue — everything needed for poison-message handling and routing logic (page 715's table).
Putting it together — the typical sequence
Dequeueing pulls a message — the read side:
- Dequeue —
OCI_DequeueGet(queue)blocks for the next message (or times out perDequeueSetWaitTime). - Read the
OCI_Msg—MsgGetattributes: payload, sender, dequeue count. - Acknowledge — dequeue modes (
OCI_DM_*) decide whether the message is consumed or just browsed. - Repeat — the dequeue loop is the consumer's heartbeat.
Hints: DM_REMOVE deletes on dequeue (default), DM_BROWSE peeks — choose
per consumer role; DequeueSetWaitTime keeps the call from blocking forever —
OCI_NOWAIT returns immediately; and high deq_count means repeated
delivery — the poison-message signal to watch.
Try it yourself
- Dequeue with
WaitTime(0)on an empty queue vsWaitTime(-1)after a enqueue. - Browse (peek) the same message twice with browse mode, then remove-mode get it.
- Filter by correlation: enqueue two messages with different correlation ids and dequeue only one.
Common pitfalls
- Consumed message not committed — rollback puts it back on the queue.
FIRST_MSGeach call — restarts the scan; useNEXT_MSGto walk forward.- Multi-consumer without consumer name — no message is delivered.
Recap
DequeueGetpulls (respecting wait/navigation/mode/visibility/consumer);Commitremoves for good;DequeueListenroutes named consumers.
Next: async dequeue callbacks and OCI_Agent publish/subscribe.