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.

no_message EXCEPTION;<br />

pragma EXCEPTION_INIT(no_message, -25254);<br />

order_msg boladm.order_typ;<br />

new_status VARCHAR2(30);<br />

monitor BOOLEAN := TRUE;<br />

begin_time NUMBER;<br />

end_time NUMBER;<br />

BEGIN<br />

begin_time := dbms_utility.get_time;<br />

WHILE (monitor)<br />

LOOP<br />

BEGIN<br />

Dequeue Features<br />

/* Construct the waiters list: */<br />

agent_list(1) := aq$_agent('BILLED_ORDER', 'CS_billedorders_que', NULL);<br />

agent_list(2) := aq$_agent('SHIPPED_ORDER', 'CS_shippedorders_que',<br />

NULL);<br />

agent_list(3) := aq$_agent('BACK_ORDER', 'CS_backorders_que', NULL);<br />

agent_list(4) := aq$_agent('Booked_ORDER', 'CS_bookedorders_que', NULL);<br />

/* Wait for order status messages: */<br />

dbms_aq.listen(agent_list, wait_time, agent_w_message);<br />

dbms_output.put_line('Agent' || agent_w_message.name || ' Address '||<br />

agent_w_message.address);<br />

/* Dequeue the message from the queue: */<br />

dequeue_message(agent_w_message.address, agent_w_message.name, order_msg);<br />

/* Update the status of the order depending on the type of the message,<br />

* the name of the agent contains the new state: */<br />

update_status(agent_w_message.name, order_msg);<br />

/* Exit if we have been working long enough: */<br />

end_time := dbms_utility.get_time;<br />

IF (end_time - begin_time > time) THEN<br />

EXIT;<br />

END IF;<br />

EXCEPTION<br />

WHEN no_message THEN<br />

dbms_output.put_line('No messages in the past 2 minutes');<br />

end_time := dbms_utility.get_time;<br />

/* Exit if we have done enough work: */<br />

IF (end_time - begin_time > time) THEN<br />

A Sample Application Using AQ 8-93

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

Saved successfully!

Ooh no, something went wrong!