Universal Messaging 10.3 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for Java | Message Queues | Queue Publish
 
Queue Publish
There are 2 types of publish available in Universal Messaging for queues:
Reliable publish is simply a one way push to the Universal Messaging Server. This means that the server does not send a response to the client to indicate whether the event was successfully received by the server from the publish call.
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 you have established a session and find a queue, you then need to construct an 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 nTransactionAttributes(myQueue);
nTransaction myTransaction=nTransactionFactory.create(tattrib);
myTransaction.publish(messages);
myTransaction.commit();
If during the transaction commit your Universal Messaging session becomes disconnected, and the commit 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 Universal Messaging Realm Server.
boolean committed = myTransaction.isCommitted(true);
Which will query the Universal Messaging Realm Server to see if the transaction was committed.