Universal Messaging Developer Guide : Web Client APIs : Web Developer's Guide for Javascript : Web Client Development in JavaScript : Publish/Subscribe Tasks : Transactional Publish
Transactional Publish
Transactional publishing provides a means of verifying that the server has received events from the publisher, and therefore provides guaranteed delivery. Clients can publish using transactions to both channels and queues in Javascript.
Transactions can be created by the user from a Universal Messaging Event object and a Universal Messaging Transaction object. The event can then be published through the transaction object to the server.

var demoSession = Nirvana.createSession();
var myChannel = demoSession.getChannel("/example/txChannel");

var dataListener = function(event) {
console.log("Received Event from Channel");

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

var myTransaction = myChannel.createTransaction();

var commitListener = function() {
console.log("Received Commit Callback from Publish");

myTransaction.on(Nirvana.Observe.COMMIT, commitListener);

var myEvent = Nirvana.createEvent();
myEvent.setData("Hello World");

The transaction's observable event Nirvana.Observe.COMMIT is fired after a successful publish request once the client receives confirmation from the server that the event has been published. This will result in the invocation of any user-assigned listener functions, as in the example code above.
Similarly, a transaction's observable event Nirvana.Observe.ERROR is fired after when the client receives confirmation from the server that a problem occurred resulting in the event not being published.

var errorListener = function(error) {

myTransaction.on(Nirvana.Observe.ERROR, errorListener);
In scenarios where a problem occurs, the client may not receive either of these callbacks. This may be either due to server side or client side failure. In these scenarios the state of the transaction from the clients perspective is ambiguous.
By invoking the myTransaction.checkCommitStatus(queryServer) method the client will attempt to resolve the state of the server. It will first attempt to do this locally; if it can do this the method will instantaneously invoke the callback method with the transaction status. If it cannot do this and queryServer is set to true, it will contact the server for confirmation and pass this confirmation to any callback method associated with the transaction's observable event Nirvana.Observe.COMMIT. If queryServer is set to false it will immediately invoke the callback with the failure status.
Copyright © 2013-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback