09.12.2012 Views

Advanced Queuing - Oracle

Advanced Queuing - Oracle

Advanced Queuing - Oracle

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Dequeue Features<br />

Scenario<br />

In the customer service component of the BooksOnLine example, messages from<br />

different databases arrive in the customer service queues, indicating the state of the<br />

message. The customer service application monitors the queues and whenever there<br />

is a message about a customer order, it updates the order status in the order_<br />

status_table. The application uses the listen call to monitor the different<br />

queues. Whenever there is a message in any of the queues, it dequeues the message<br />

and updates the order status accordingly.<br />

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

CODE (in tkaqdocd.sql)<br />

/* Update the status of the order in the order status table: */<br />

CREATE OR REPLACE PROCEDURE update_status(<br />

new_status IN VARCHAR2,<br />

order_msg IN BOLADM.ORDER_TYP)<br />

IS<br />

old_status VARCHAR2(30);<br />

dummy NUMBER;<br />

BEGIN<br />

BEGIN<br />

/* Query old status from the table: */<br />

SELECT st.status INTO old_status FROM order_status_table st<br />

WHERE st.customer_order.orderno = order_msg.orderno;<br />

/* Status can be 'BOOKED_ORDER', 'SHIPPED_ORDER', 'BACK_ORDER'<br />

and 'BILLED_ORDER': */<br />

IF new_status = 'SHIPPED_ORDER' THEN<br />

IF old_status = 'BILLED_ORDER' THEN<br />

return; /* message about a previous state */<br />

END IF;<br />

ELSIF new_status = 'BACK_ORDER' THEN<br />

IF old_status = 'SHIPPED_ORDER' OR old_status = 'BILLED_ORDER' THEN<br />

return; /* message about a previous state */<br />

END IF;<br />

END IF;<br />

/* Update the order status: */<br />

UPDATE order_status_table st<br />

SET st.customer_order = order_msg, st.status = new_status;<br />

A Sample Application Using AQ 8-91

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

Saved successfully!

Ooh no, something went wrong!