Asynchronous Transactional Queue Consuming
Transactional queue consumers have the ability to notify the server when events have been consumed (committed) or when they have been discarded (rolled back). This ensures that the server does not remove events from the queue unless notified by the consumer with a commit or rollback.
Subscribing as a Transactional Reader
var demoSession = Nirvana.createSession();
var demoQueue = demoSession.getQueue ("/some/demo/queue");
// define what to do when we receive an event
You can specify the transaction flag and the window size as follows:
var demoQueue = mySession.getQueue ("/some/demo/queue", true);
// The true flag specifies that we are a transactional reader
demoQueue.setWindowSize(10); // 10 is the windowSize
Performing a Commit
As previously mentioned, the big difference between a transactional reader and a standard queue reader is that once events are consumed by the reader, the consumers need to commit the events consumed. Events will only be removed from the queue once the commit has been called.
The server will only deliver up to the specified windowSize number of events. After this the server will not deliver any more events to the client until commit has been called. The default windowSize is 5.
// process the event
demoQueue.commit(event); // Commit the event
Performing a Rollback
Developers can also roll back events received by the transactional reader. Uncommitted events will be redelivered by the server (possibly to other queue consumers if they exist).