Universal Messaging 10.3 | Developer Guide | Web Client APIs | Web Developer's Guide for Javascript | Web Client Development in JavaScript | Publish/Subscribe Tasks | Using a Universal Messaging Channel
 
Using a Universal Messaging Channel
This JavaScript code snippet demonstrates how to create a channel object, which allows you to publish or subscribe to a Universal Messaging channel:

var myChannel = mySession.getChannel("/fxdemo/prices");
Note that unlike the Enterprise APIs, the JavaScript API does not support programmatic creation of channels; instead, you can use the Enterprise Manager GUI to create a Universal Messaging Channel.
A channel object offers several methods. Three of the more important ones are:
*myChannel.subscribe()
*myChannel.unsubscribe()
*myChannel.publish(Event event)
Please see JavaScript API Documentation for Channels for information on all available methods on a channel.
Each of the above methods can invoke one or more optional user-specified callback functions which you can (and probably should) implement and assign as follows:

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

// Assign a handler function for Universal Messaging Events received on the Channel,
// then subscribe:
function myEventHandler(event) {
var dictionary = event.getDictionary();
console.log(dictionary.get("name") + " " + dictionary.get("bid"));
}

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

myChannel.subscribe();

See Subscribing to a Channel and Publishing Events to a Channel.