09.12.2012 Views

Advanced Queuing - Oracle

Advanced Queuing - Oracle

Advanced Queuing - Oracle

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Enqueue Features<br />

Message Properties]" on page 11-9 in Chapter 11, "Operational Interface: Basic<br />

Operations"). The delay interval determines when an enqueued message is marked<br />

as available to the dequeuers after the message is enqueued.<br />

When a message is enqueued with a delay time set, the message is marked in a<br />

WAIT state. Messages in WAIT state are masked from the default dequeue calls. A<br />

background time-manager daemon wakes up periodically, scans an internal index<br />

for all WAIT state messages, and marks messages as READY if their delay time has<br />

passed. The time-manager will then post to all foreground processes that are<br />

waiting on queues for messages that have just been made available.<br />

Scenario<br />

In the BooksOnLine application, delay can be used to implement deferred billing. A<br />

billing application can define a queue where shipped orders that are not billed<br />

immediately can be placed in a deferred billing queue with a delay. For example, a<br />

certain class of customer accounts, such as those of corporate customers, may not be<br />

billed for 15 days. The billing application dequeues incoming shipped order<br />

messages (from the shippedorders queue) and if the order is for a corporate<br />

customer, this order is enqueued into a deferred billing queue with a delay.<br />

PL/SQL (DBMS_AQADM Package): Example Code<br />

/* Enqueue an order to implement deferred billing so that the order is not made<br />

visible again until delay has expired: */<br />

CREATE OR REPLACE PROCEDURE defer_billing(deferred_billing_order order_typ)<br />

AS<br />

defer_bill_queue_name VARCHAR2(62);<br />

enqopt dbms_aq.enqueue_options_t;<br />

msgprop dbms_aq.message_properties_t;<br />

enq_msgid RAW(16);<br />

BEGIN<br />

/* Enqueue the order into the deferred billing queue with a delay of 15 days: */<br />

defer_bill_queue_name := 'CBADM.deferbilling_que';<br />

msgprop.delay := 15*60*60*24;<br />

dbms_aq.enqueue(defer_bill_queue_name, enqopt, msgprop,<br />

deferred_billing_order, enq_msgid);<br />

END;<br />

/<br />

Visual Basic (OO4O): Example Code<br />

set oraaq = OraDatabase.CreateAQ("CBADM.deferbilling_que")<br />

Set OraMsg = OraAq.AQMsg(ORATYPE_OBJECT, "BOLADM.order_typ")<br />

8-46 <strong>Oracle</strong>9i Application Developer’s Guide - <strong>Advanced</strong> <strong>Queuing</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!