Universal Messaging 9.10 | Universal Messaging Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Message Queues | Queue Publish
 
Queue Publish
There are 2 types of publish available in Universal Messaging for queues:
*Reliable Publish
*Transactional Publish
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 found a queue, you then need to construct an event (see Universal Messaging Events) 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(), size);
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 (see Creating a Session) and our queue (see Finding a Queue), we then need to construct our events (see Universal Messaging 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:

std::list<nConsumeEvent*> messages;
messages->push_back(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, a 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.

bool committed = myTransaction->isCommitted(true);
Which will query the Universal Messaging Realm Server to see if the transaction was committed.
An example of publishing events onto a queue can be found on the examples page under "Push Queue". An example of how to transactionally publish events to a queue can be found on the examples page under "TX Push Queue".

Copyright © 2013-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.