Skip Headers

Oracle® Objects for OLE Developer's Guide

Part Number B10952-01
Go To Table Of Contents

Monitoring Messages

The OraAQ Monitor methods (MonitorStart and MonitorStop) provide asynchronous dequeuing through notifications. This is suitable for applications that prefer to process messages in non-blocking mode. Applications can request to be notified on arrival of messages, by supplying an Automation object to the Monitor method. This object implements a method called NotifyMe to receive notifications. Messages can be monitored based on consumer name, message Id, or correlation.

The following sample code demonstrates a simple usage of this facility. It illustrates a computerized trading system that executes buy/sell limit orders.

The sample instantiates a queue object for the queue STOCKS_TO_TRADE and monitors messages intended for consumer BROKER_AGENT. STOCKS_TO_TRADE queues messages of the user-defined type TRADEORDER_TYPE. This encapsulates all the information required to kick off a trade order. When messages addressed to BROKER_AGENT are dequeued, the NotifyMe method of the CallbackClient object is invoked and a stock trade is performed.

'First instantiate the CallbackClient. The queue monitor

' will invoke the NotifyMe on this class module.

Public CB_Client As New CallbackClient

Dim DB As OraDatabase

Dim Q as OraAQ

set Q = DB.CreateAQ("STOCKS_TO_TRADE")

'Notify by calling cbclient::NotifyMe when there are messages

' for consumer '"BROKER_AGENT"

Q.consumer = "BROKER_AGENT"

'Note that cbclient is a dispatch interface that

' supports the NotifyMe method.

Dim s as string


'Notify the client only when there are messages for "BROKER_AGENT"

Q.MonitorStart CB_Client, Q, s, 1

'other processing is performed here...



'Now implement the NotifyMe method of the CallbackClient class module

'and the necessary arguments that will contain the dequeued message

'NotifyMe is the callback interface defined by user. Ctx here is the

'Q object passed in at the time of MontiorStart.

Public sub NotifyMe (ByVal Ctx As Variant, ByVal Msgid As Variant )

On Error GoTo NotifyMeErr

Dim tradingSignal as OraAQMsg

'Tradeorder contains details of the customer order

Dim tradeorder as OraObject

If IsNull(Msgid) Then

MsgBox "No Message"

'Get Error

MsgBox OraDatabase.LastServerErrText


mvarMsgid = Msgid

Set tradingSignal = Ctx.AQMsg(1,"STOCK_TYPE","TRADER")

set tradeorder = tradingSignal.Value

'Tradeorder is the object of UDT "STOCK_TYPE"

'Access signal attribute of tradeorder as

'tradeorder("signal).Value or tradeorder!signal

if (tradeorder!signal = "SELL")

'Sell the stock




else if (tradeorder!signal = "BUY")

'Buy the stock




end if

End If


Call RaiseError(MyUnhandledError, "newcallback:NotifyMe Method")

End Sub

Copyright © 1994, 2003 Oracle Corporation.

All Rights Reserved.
Go To Table Of Contents