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.
Q.MonitorStart CB_Client
'other processing is performed here...
Q.MonitorStop
Return
'Now implement the NotifyMe method of the CallbackClient class module
'and the necessary arguments that will contain the dequeued message
OraAQMsg ( out )
Public sub NotifyMe (OraAQMsg tradingSignal)
'Tradeorder contains details of the customer order
Dim tradeorder as OraObject
set tradeorder = tradingSignal.Value
if (tradeorder!signal = "SELL")
' Sell the stock
SellStock(tradeorder!NoOfShares,
tradeorder!Ticker,tradeorder!Price,tradeorder!ValidUntil)
else if (tradeorder!signal = "BUY")
buy the stock
BuyStock(tradeorder!NoOfShares,
tradeorder!Ticker,tradeorder!Price,tradeorder!ValidUntil)
End Sub