routeEvent

Syntax

routeEvent(event)

Details

A routed event sent by routeEvent goes to the front of the input queue. The engine processes all routed events before it processes the next non-routed event on the input queue.

Parameters

event is an event instance.

Returns

None

Examples

Define the events:
class UpdateFactor{
    sym :: STRING
    factor :: DOUBLE
    def UpdateFactor(code, val){
        sym = code
        factor = val
    }
}

class MarketData{
    market :: STRING
    code :: STRING
    price :: DOUBLE
    qty :: INT
    def MarketData(m,c,p,q){
        market = m
        code = c
        price = p
        qty = q
    }
}
Define the monitor:

class MainMonitor : CEPMonitor{
    maxPrice :: DOUBLE

    def MainMonitor(){ maxPrice = 0.0 }
    
    def updateMarketData(event)
  
    def onload(){
        addEventListener(handler=updateMarketData, eventType='MarketData', times='all')
    }

    def updateMarketData(event){
        print("MarketData: "+event.code+" price="+string(event.price))

        if(event.price > maxPrice){
            maxPrice = event.price

            // emitEvent:Output to streaming table
            emitEvent(UpdateFactor("maxPrice", maxPrice))

            // routeEvent: inserts a warning event at the head of the queue for priority processing
            routeEvent(UpdateFactor("alert", maxPrice))

            // sendEvent: inserts an informational event at the tail of the queue for sequential processing
            sendEvent(UpdateFactor("info", maxPrice))
        }
    }
}
Create a streaming table to receive output events:
share streamTable(array(STRING,0) as eventType, array(BLOB,0) as blobs) as simulateResult

serializer = streamEventSerializer(
    name=`simulate,
    eventSchema=[UpdateFactor],
    outputTable=simulateResult
)

dummy = table(array(STRING,0) as eventType, array(BLOB,0) as blobs)
Create a CEP engine:
engine = createCEPEngine(
    name='cep1',
    monitors=<MainMonitor()>,
    dummyTable=dummy,
    eventSchema=[MarketData],
    outputTable=serializer
)

Related functions: addEventListener, createCEPEngine, appendEvent, emitEvent, sendEvent