Transactional support

Transactional behavior for all interaction patterns is supported with the following conditions.

In the HubRequest pattern, the sending of the message and waiting for and receiving of the response must not be part of one transaction. If one transaction is used, the J2EE component will block indefinitely, since no message can be received until one is sent, which only happens when the transaction is committed.

A special care must be taken when transactions are used with the patterns that originate from the agent (AgentDelivery and AgentRequest) to prevent disabling of the message listener. When the MDB receives an agent-originated message and an exception is thrown in MDB or any other WebSphere Application Server component it invokes, the transaction is rolled back and the message is put back in the queue and then redelivered. If the error continues, the redelivery either stops after a predefined number of attempts, disabling the listener, or continues indefinitely (depending on the listener port setting). To prevent this situation, if transactions are used, the user should add user code to the MDB to detect and handle the redelivered messages. The sample below shows how the redelivered message can be detected in the MDB.

	public void onMessage(javax.jms.Message msg) {
     		try {
// -> new code start
			       if(msg.getJMSRedelivered()){
          				System.out.println("Message redelivered");
				          // User code to handle redelivered message 
			          }
			          else{
          				System.out.println("Message delivered first time");
				        // First time delivery, unless user code for
        				  // redelivery returns, it should invoke
    executeOperation(msg)
         			}
// <- new code end
    			executeOperation(msg);
  		}
		catch (WSIFException e) {
    			e.printStackTrace();
  		}
		catch (javax.jms.JMSException e) {
    					e.printStackTrace();
		  }
	}

Copyright IBM Corp. 1997, 2003