Nirvana Python : Nirvana Events
A Nirvana Event (nConsumeEvent) is the object that is published to a Nirvana Channel, Queue, DataGroup or P2P service. It is stored by the server and then passed to consumers as and when required.
Events can contain simple byte array data, or more complex data structures such as an Nirvana Event Dictionary (nEventProperties).
Constructing an Event
In this Python code snippet, we construct our Nirvana Event object (nConsumeEvent), as well as a Nirvana Event Dictionary object (nEventProperties) for our Nirvana Event:
props = nEventProperties()
props.put("bondname", "bond1")
props.put("price", 100.00)
event = nConsumeEvent(props,"Tag")
Handling a Received Event
When a client subscribes to a channel and specifies a callback function to handle received events, the callback function will be invoked with the event as its parameter whenever an event is received.
In this Python code snippet, we demonstrate a simple implementation of such a callback function. In this example, we assume that the event contains an Event Dictionary with two keys: bondname and price.
class myCallback(NirvanaPython.NirvanaCallback):
def onMessage(self,event):
props = event.getProperties()
name = props.get("bondname")
price = props.get("price")
//do something with name and price
