Universal Messaging 10.11 | Developer Guide | Web Client APIs | Web Developer's Guide for Javascript | JavaScript Objects | Universal Messaging Events
 
Universal Messaging Events
A Universal Messaging Event is the object that is published to a Universal Messaging channel or queue. 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 Universal Messaging Event Dictionary.
Constructing an Event
In this JavaScript code snippet, we construct our Universal Messaging Event object, as well as a Universal Messaging Event Dictionary object for our Universal Messaging Event:

var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("demoMessage", "Hello World");
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 JavaScript 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.

var myChannel = mySession.getChannel("/fxdemo/prices");

function myEventHandler(event) {
var dictionary = event.getDictionary();
console.log(dictionary.get("name") + ": " + dictionary.get("price"));
}

myChannel.on(Nirvana.Observe.DATA, myEventHandler);

myChannel.subscribe();