Universal Messaging JavaScript : Using a Universal Messaging Queue
This JavaScript code snippet demonstrates how to create a queue object, which allows you to publish or subscribe to a Universal Messaging queue:
var myQueue = mySession.getQueue("/demo/prices");
Note that unlike the Enterprise APIs, the JavaScript API does not support programmatic creation of queues; instead, you can use the Enterprise Manager GUI to create a Universal Messaging Queue.
A queue object offers several methods. Three of the more important ones are:
myQueue.subscribe() myQueue.unsubscribe() myQueue.publish(Event event) Please see JavaScript API Documentation for Queues for information on all available methods on a queue.
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 myQueue = mySession.getQueue("/demo/prices");
// Assign a handler function for Universal Messaging Events received on the Queue, then subscribe:
function myEventHandler(event) {
var dictionary = event.getDictionary();
console.log(dictionary.get("name") + " " + dictionary.get("bid"));
}
myQueue.on(Nirvana.Observe.DATA, myEventHandler);
myQueue.subscribe();