Universal Messaging 9.12 | Developer Guide | Enterprise APIs | Enterprise Developer's Guide for C# | Message Queues | Publishing events to a Queue
 
Publishing events to a Queue
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 the session has been established with the Universal Messaging realm server and the queue has been located, an event must be constructed prior to a publish call being made to the queue.
The following code snippet shows how to reliably publish events to a queue. Further examples can be found in the API documentation.

// Publishing a simple byte array message
myChannel.publish(new nConsumeEvent("TAG", (new UTF8Encoding()).GetBytes(message)));

// Publishing multiple messages in one publish call
List Messages = new List();
Messages.Add(message1);
Messages.Add(message2);
Messages.Add(message3);
myChannel.publish(Messages);
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, then publish these events to the transaction. The transaction will then be committed and the events available to consumers to the queue.
Below is a code snippet demonstrating transactional publishing:

List Messages = new List();
Messages.Add(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 whether a transaction has been committed or aborted, the transaction can be queried to determine whether the events within the transactional were successfully received by the Universal Messaging Realm Server:

bool committed = myTransaction.isCommitted(true);
Examples
For more information on Universal Messaging Message Queues, please see the API documentation.

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.