Example UOW Producer Code UOW Exceptions

Using Unit-of-Work Message Groups 11-5 it is easiest to envision them as a single virtual message, as well as individual messages. In order for WebLogic JMS to identify a message as part of a UOW, the message must have the JMS properties in Table 11–1 set by the producer client. If the UnitOfWork property is not set, then SequenceNumber and End will be ignored.

11.3.1.1 Example UOW Producer Code

The following sample client code sample sets the UOW properties defined in Table 11–1 . Example 11–1 Sample UOW Producer Message Properties for int i=1; i=100; i++ { sendMsg.setStringPropertyJMS_BEA_UnitOfWork,joule; sendMsg.setIntPropertyJMS_BEA_UnitOfWorkSequenceNumber,i; if i == 100 { System.out.printlnset the end of message flag for message + i; sendMsg.setBooleanPropertyJMS_BEA_IsUnitOfWorkEnd,true; } qSender.sendsendMsg, DeliveryMode.PERSISTENT,7,0; } Table 11–2 Unit-of-Work Properties Type Description JMS_BEA_UnitOfWork A string property that is set by the standard JMS mechanism for setting properties. For example: message.setStringPropertyJMS_BEA_UnitOfWork, MyUnitOfWorkName To avoid naming conflicts, the UOW ID should never be reused. For example, if messages are lost or retransmitted, then they may be perceived as part of a separate UOW. For this reason, Oracle recommends using a Java universally unique identifier UUID. See http:java.sun.comj2se1.5.0docsapijavaut ilUUID.html . JMS_BEA_ UnitOfWorkSequenceNumber An integer property that is set by the standard JMS mechanism for setting properties. For example, message.setIntPropertyJMS_BEA_ UnitOfWorkSequenceNumber, 5 The legal values are integers greater than or equal to 1 JMS_BEA_IsUnitOfWorkEnd A boolean property that is set by the standard JMS mechanism for setting properties. For example: message.setBooleanPropertyJMS_BEA_IsUnitOfWorkEnd, true When this property is true, the message is the last in the unit-of-work. When this property is false or nonexistent, the message is not last in the unit-of-work. 11-6 Programming JMS for Oracle WebLogic Server

11.3.1.2 UOW Exceptions

The following exceptions may be thrown to the producer when sending JMS messages to a terminal destination. When a UOW exception is town, the UOW message is not delivered. Except for the last one, they are all in the weblogic.jms.extensions package and are subclasses of JMSException. ■ BadSequenceNumberException – This will occur if a UnitOfWork is set on the message, but SequenceNumber is not or b the SequenceNumber is less than or equal to zero. ■ OutOfSequenceRangeException – This will be thrown if a a message is sent with a SequenceNumber that is higher than the sequence number of the message which has already been marked as the end of the unit or b a message is sent with a sequence number which is lower than a message which has already arrived in the same unit, yet the new message is marked as the end message. ■ DuplicateSequenceNumberException – This will be thrown to the producer if it sends a message with a sequence number which is the same as a previously sent message in the same UOW. ■ JMSException – A JMS exception will be thrown if a message has both the UnitOfOrder property set and the UnitOfWork property set.

11.3.2 How to Write a UOW ConsumerProducer For an Intermediate Destination