Nirvana Flex : Nirvana Events

A Nirvana Event (nConsumeEvent) is the object that is published to a Nirvana channel, queue 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 Flex code snippet, we construct our Nirvana Event object (nConsumeEvent), as well as a Nirvana Event Dictionary object (nEventProperties) for our Nirvana Event:

var event : nConsumeEvent = new nConsumeEvent();
var dictionary : nEventProperties = new nEventProperties();
dictionary.put("exampleKey", "Hello World");
event.properties = dictionary;

Handling a Received Event

When a client subscribes to a channel and specifies the callback listener to handle received events, the listener will be invoked with the event as its parameter whenever an event is received.

In this Flex 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: name and price.

function eventHandlerCallbackFunc(event:nConsumeEvent) {
	var dictionary : nEventProperties = event.properties;
	var name : String = dictionary.get("name");
	var price = dictionary.get("price");
	trace("Name = " + name + " and Price = " + price);
}