Universal Messaging 9.12 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C++ | Publish / Subscribe using Channel Topics | How to publish events to a Channel
 
How to publish events to a Channel
There are 2 types of publish available in Universal Messaging for channels:
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 the session has been established with the Universal Messaging realm server and the channel has been located, an event must be constructed prior to a publish call being made to the channel.
For reliable publish, there are a number of method prototypes on a channel that allow us to publish different types of events onto a channel. Here are examples of some of them. Further examples can be found in the API documentation.

// Publishing a simple byte array message
myChannel->publish(new nConsumeEvent("TAG", message->getBytes()));

Transactional Publish
Transactional publishing provides a means of verifying that the server received the events from the publisher, and therefore provides guaranteed delivery.
There are similar prototypes available to the developer for transactional publishing. Once the session is established and the channel located, we then need to construct the events for the transaction and publish these events to the transaction. Only when the transaction has been committed will the events become available to subscribers on the channel.
Below is a code snippet for transactional publishing:
std::list<nConsumeEvent*> messages;
messages->push_back(message1);
nTransactionAttributes *tattrib=new nTransactionAttributes(myChannel);
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 transaction were successfully received by the Universal Messaging Realm Server. This call can be made regardless of whether the connection was lost and a new connection was created.
The following code snippet demonstrates how to query the Universal Messaging Realm Server to see if the transaction was committed:
bool committed = myTransaction->isCommitted(true);

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.