Universal Messaging 10.11 | Developer Guide | Web Client APIs | Web Developer's Guide for Javascript | Web Client Development in JavaScript | Message Queue Tasks | Publishing Events to a Queue
 
Publishing Events to a Queue
Once the session has been established with the Universal Messaging realm server, and a Universal Messaging Queue object has been created, a new Universal Messaging Event object must be constructed to use in the publish call being made on the queue.
Note that in this example code, we also create a Universal Messaging Event Dictionary object for our Universal Messaging Event before publishing it:

var mySession = Nirvana.createSession();
var myQueue = mySession.getQueue("/tutorial/somequeue");
var myEvent = Nirvana.createEvent();
var myDict = myEvent.getDictionary();
myDict.putString("demoMessage", "Hello World");
myQueue.publish(myEvent);
Note that the publish call is asynchronous; it returns immediately, allowing single-threaded JavaScript clients to continue processing.
To enable the developer to know when a publish call has completed, any user function assigned as a callback for the queue's observable event Nirvana.Observe.PUBLISH will be invoked, with the a string value of "OK" (which indicates the publish was successful):

function publishCB(responseString) {
console.log("Publish attempt: " + responseString);
}
myQueue.on(Nirvana.PUBLISH, publishCB);
myQueue.publish(myEvent);