|
Transactional publish involves creating a transaction
object to which events are published, and then committing
the transaction. The server responds to the transaction
commit call indicating if it was successful. There are
also means for transactions to be checked for status
after application crashes or disconnects.
Reliable
Publish
Once we have established our session
and our queue, we then
need to construct our
event and publish the event onto the queue.
For reliable publish, here is the example code for
how to publish events to a queue. Further examples can
be found in the API documentation.
// Publishing a simple
byte array message
myQueue.push(new nConsumeEvent("TAG", message.getBytes()));
// publishiing an XML document
InputStream is = new FileInputStream( aFile
);
DOMParser p = new DOMParser();
p.parse( new InputSource( is ) );
Document doc = p.getDocument();
myQueue.push( "XML", doc );
Transactional Publish
Transactional publishing provides us with a method
of verifying that the server receives the events from
the publisher, and provides guaranteed delivery.
There are similar prototypes available to the developer
for transaction publishing. Once we have established
our session and
our queue, we then need
to construct our events
and our transaction and publish these events to the
transaction. Then the transaction will be committed
and the events available to consumers to the queue.
Below is a code snippet of how transactional publishing
is achieved:
Vector messages=new Vector();
Messages.addElement(message1);
nTransactionAttributes tattrib=new nTransasctionAttributes(myQueue);
nTransaction myTransaction=nTransactionFactory.create(tattrib);
myTransaction.publish(messages);
myTransaction.commit();
If during the transaction commit your Nirvana session
becomes disconnected, and the commmit call throws an
exception, the state of the transaction may be unclear.
To verify that a transaction has been committed or aborted,
an call can be made on the transaction that will determine
if the events within the transactional were successfully
received by the Nirvana Realm Server.
boolean committed = myTransaction.isCommitted(true);
Which will query the Nirvana Realm Server to see if
the transaction was committed.
An example of publishing events onto a queue can be
found here.
An example of how to transactionally publish events
to a queue can be found here.
For more information on Nirvana message queues, please
see the API documentation. |